Search code examples
mysqlsqlsql-delete

MySQL delete "inactive" rows


I've got 2 tables:

user

id | name | mail | pass | salt

entries

id | uid | title | text | timestamp

Now I want to delete all rows of entries with an uid, which doesn't exist in user-table (deleted users)

I think this might work like this:

DELETE entries FROM user, entries WHERE [What comes here? I don't know :(]

Solution

  • DELETE FROM entries WHERE uid NOT IN (SELECT DISTINCT id FROM user);