Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :(]
like image 273
ninov Avatar asked Mar 26 '26 06:03

ninov


1 Answers

DELETE FROM entries WHERE uid NOT IN (SELECT DISTINCT id FROM user);
like image 145
Travesty3 Avatar answered Mar 28 '26 20:03

Travesty3