如何结合MySQL查询?

时间:2013-09-29 17:38:26

标签: mysql

如何组合MySQL查询以删除表中列数据等于其他表的SELECT的行?

我想到: DELETE FROM debts WHERE name = (SELECT name FROM payers)

1 个答案:

答案 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