0

I'd like to convert the following

SELECT * `members` m
WHERE NOT EXISTS
  (SELECT s.mid
   FROM   memberships s 
   WHERE  s.mid = m.id);

to the equivalent delete statement. However, the code below doesn't work:

DELETE FROM `members` m
WHERE NOT EXISTS
  (SELECT s.mid
   FROM   memberships s 
   WHERE  s.mid = m.id);

1 Answer 1

2

You can use the multiple-table DELETE syntax to perform an outer join between the tables:

DELETE FROM members
USING members LEFT JOIN memberships ON memberships.mid = members.id
WHERE memberships.mid IS NULL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.