SQL Delete: 根据多个条件删除数据
简单删除
DELETE TABLE_NAME WHERE KEY = 1; DELETE TABLE_NAME WHERE KEY IN (1, 2, 3); DELETE TABLE_NAME WHERE KEY IN (SELECT 1 FROM DUAL);
多条件删除
1.EXISTS
DELETE FROM TABLE_NAME ORIGIN WHERE EXISTS ( SELECT * FROM ( SELECT KEY1, KEY2 FROM TABLE_NAME GROUP BY KEY1, KEY2 ) SOURCE WHERE ORIGIN.KEY1 = SOURCE.KEY1 AND ORIGIN.KEY2 = SOURCE.KEY2 );
2.IN
DELETE FROM TABLE_NAME WHERE (KEY1, KEY2) IN ( SELECT KEY1, KEY2 FROM TABLE_NAME GROUP BY KEY1, KEY2 );
PS
1.NULL 只能被 IS 匹配
Reference