Reputation: 8487
I have a table delete_requests where I store the id's for delete requests for the entries of my users table. Is it possible to delete from users with the information from delete_requests as a condition?
My problem is, that the result set will usually not be limited to one row but return several.
DELETE FROM users WHERE id=(SELECT id FROM delete_requests)
So MySQL complains:
#1242 - Subquery returns more than 1 row
Can this be done in one statement without putting the logic into the executing application?
Upvotes: 0
Views: 2020
Reputation: 86466
Use the IN clause
DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)
Upvotes: 5
Reputation: 160943
You can use the in clause.
DELETE FROM users WHERE id IN (SELECT id FROM delete_requests)
Upvotes: 2