Reputation:
I have a USERS
table with active and inactive users and I also have another table called Leaders
where team leaders are stored (so a list of users).
I want to delete those users in table Leaders
that are inactive in table users
.
Edit based on comments:
Users
table: ID and ActiveLeaders
table: IDUpvotes: 2
Views: 82
Reputation: 184
You can make joins in delete, similar to select:
delete ld
from leaders ld
join users us on ld.idUser = us.idUser
where us.active = 0
Upvotes: 2
Reputation: 311028
You could use an in
condition:
DELETE
FROM leaders
WHERE id IN (SELECT id
FROM users
WHERE active = 0 -- Or however you mark inactive users
)
Upvotes: 3