如何组合MySQL查询以删除表中列数据等于其他表的SELECT的行?
我想到:
DELETE FROM debts WHERE name = (SELECT name FROM payers)
答案 0 :(得分:1)
不使用=
,而是将其更改为IN
,因为子查询可以返回多行。
DELETE FROM debts WHERE name IN (SELECT name FROM payers)
但我更喜欢JOIN
表而不是使用IN
。
DELETE a
FROM debts a
INNER JOIN payers b
ON a.name = b.name