我有3个表MySQL(MyIsam):
user (id), message (id, userId, ...), archivedMessage (id, userId, ...)
如何删除所有没有消息且没有archivedMessage的用户?
答案 0 :(得分:15)
您可以使用not exists
:
delete from user
where not exists (select * from message m where m.userid = user.id)
and not exists (select * from archivedMessage am where am.userid = user.id)