我有一个表,我需要删除两列的行,例如
+------+------+--------+
| col1 | col2 | other |
+------+------+--------+
| 12 | 2 | test |
+------+------+--------+
| 14 | 2 | test1 |
+------+------+--------+
| 12 | 3 | test2 |
+------+------+--------+
| 13 | 3 | test3 |
+------+------+--------+
| 15 | 4 | test4 |
+------+------+--------+
我希望删除(col1,col2)对等于(12,2),(13,3),(14,2)
中任何值的行我可以通过纯SQL执行此操作吗?
答案 0 :(得分:4)
如果您有很多值,请使用它们填充表并执行:
DELETE t
FROM Table t
INNER JOIN TempTable tt
ON t.col1 = tt.col1
AND t.col2 = tt.col2
答案 1 :(得分:1)
尝试以下sql:
delete from <tablename>
where (col1 = 12 and col2 = 2)
or (col1 = 13 and col2 = 3)
or (col1 = 14 and col2 = 2)