在MySQL中使用ID从表中删除许多行 [英] Delete many rows from a table using id in Mysql
问题描述
我是Linux管理员,仅具有Mysql查询中的基本知识
I am a Linux admin with only basic knowledge in Mysql Queries
我想使用 id 从我的表中删除许多IP地址表条目,
I want to delete many table entries which are ip address from my table using id,
当前我正在使用
DELETE from tablename where id=1;
DELETE from tablename where id=2;
但是我必须删除254个条目,因此此方法将要花费数小时,我如何告诉mysql删除我指定的行,因为我想跳过删除这254个条目中的某些条目.
but i have to delete 254 entries,so this method is going to take hours,how can i tell mysql to delete rows that i specify,coz i want to skip deleting some entries out of this 254.
删除整个表并导入所需的条目是不可能的.
Deleting whole table and importing needed entries is not an option.
推荐答案
最好的方法是使用IN
语句:
The best way is to use IN
statement :
DELETE from tablename WHERE id IN (1,2,3,...,254);
如果您有连续的ID,也可以使用BETWEEN
:
You can also use BETWEEN
if you have consecutive IDs :
DELETE from tablename WHERE id BETWEEN 1 AND 254;
您当然可以使用其他WHERE子句来限制某些ID:
You can of course limit for some IDs using other WHERE clause :
DELETE from tablename WHERE id BETWEEN 1 AND 254 AND id<>10;
这篇关于在MySQL中使用ID从表中删除许多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!