0

我想转换以下

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);
4

1 回答 1

2

您可以使用多表DELETE语法在表之间执行外连接:

DELETE FROM members
USING members LEFT JOIN memberships ON memberships.mid = members.id
WHERE memberships.mid IS NULL
于 2012-06-06T16:36:17.163 回答