SQL语法:使用值(id)删除多个行

时间:2016-01-25 15:24:33

标签: mysql sql-delete

在同一个表中删除特定行数(例如,从id_1到id_10)的MySQL语法是什么?

另外,如果我不想删除id_5,我会使用什么语法?

2 个答案:

答案 0 :(得分:1)

表示不删除id_5

delete from table where id != 'id_5' 

删除列表

delete from table where id in ('id_1', 'id_2', 'id_3', 'id_4', 
       'id_6', 'id_7', 'id_8', 'id_9', 'id_10');

用于删除有序范围

delete from table where id between 'id_1' and 'id_10';

或合并

delete from table where id between 'id_1' and 'id_10' and id!='id_5';

答案 1 :(得分:1)

要使用范围删除并跳过值:

DELETE
FROM yourtable
WHERE id BETWEEN 1 AND 10 AND id !=5