Reputation: 542
I want to delete all records in table participant_vote where the id matches the id of another table row.
Can this be done in one query?
This is the query I have now which returns the error that my subselect contains multiple rows
DELETE FROM
participant_vote
WHERE id = (SELECT id FROMvote
WHEREfacebookid
= :facebookid)
Upvotes: 1
Views: 69
Reputation: 171188
DELETE FROM participant_vote WHERE id IN (SELECT id FROM vote WHERE facebookid = :facebookid)
IN
being the trick. My feeling is that searching for the message would also have provided an answer.
Upvotes: 2
Reputation: 154685
Yes. Use the IN
operator instead of the =
operator.
DELETE FROM participant_vote
WHERE id IN (
SELECT id
FROM vote
WHERE facebookid = :facebookid
)
Upvotes: 2