Sql 按表中存在的列对删除行
例如,我有一个表,需要按两列删除行Sql 按表中存在的列对删除行,sql,sqlite,delete-row,sql-delete,Sql,Sqlite,Delete Row,Sql Delete,例如,我有一个表,需要按两列删除行 +------+------+--------+ | col1 | col2 | other | +------+------+--------+ | 12 | 2 | test | +------+------+--------+ | 14 | 2 | test1 | +------+------+--------+ | 12 | 3 | test2 | +------+------+--------+ | 13
+------+------+--------+
| 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来实现这一点吗 尝试以下sql:
delete from <tablename>
where (col1 = 12 and col2 = 2)
or (col1 = 13 and col2 = 3)
or (col1 = 14 and col2 = 2)
从中删除
式中(col1=12和col2=2)
或(col1=13和col2=3)
或(col1=14和col2=2)
如果您有很多值,请用它们填充表格并执行以下操作:
DELETE t
FROM Table t
INNER JOIN TempTable tt
ON t.col1 = tt.col1
AND t.col2 = tt.col2
嗨,我有很多对必须删除,我希望能够使用像“在”声明的东西。没有其他解决方案?请参阅JNK提供的解决方案。您使用的是哪个数据库管理器?请注意,此解决方案不适用于sqlite。请参见sqlite的SO解决方案: