ninov
ninov

Reputation: 639

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 :(]

Upvotes: 3

Views: 525

Answers (1)

Travesty3
Travesty3

Reputation: 14479

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

Upvotes: 7

Related Questions