skrln
skrln

Reputation: 542

Delete multiple rows

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 FROM vote WHERE facebookid = :facebookid)

Upvotes: 1

Views: 69

Answers (2)

usr
usr

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

Mark Amery
Mark Amery

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

Related Questions