2016-01-25 47 views
0

在同一個表中刪除一定數量的行(例如從id_1到id_10)的MySQL語法是什麼?SQL語法:使用值(id)刪除多行

此外,如果我不想刪除id_5,我將使用什麼語法?

+1

的【如何一次刪除的記錄範圍 - MySQL的]可能的複製(http://stackoverflow.com/questions/7972435/how-to- delete-range-of-records-at-once-mysql) – ahoffner

回答

1

要刪除與範圍,並跳過一個值:

DELETE 
FROM yourtable 
WHERE id BETWEEN 1 AND 10 AND id !=5 
+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'; 
+0

感謝您的額外信息,將有所幫助。 –