我想转换以下内容
SELECT * `members` m
WHERE NOT EXISTS
(SELECT s.mid
FROM memberships s
WHERE s.mid = m.id);
到等效的删除语句。但是,下面的代码不起作用:
DELETE FROM `members` m
WHERE NOT EXISTS
(SELECT s.mid
FROM memberships s
WHERE s.mid = m.id);
答案 0 :(得分:2)
您可以使用多表DELETE
语法在表之间执行外连接:
DELETE FROM members
USING members LEFT JOIN memberships ON memberships.mid = members.id
WHERE memberships.mid IS NULL