2013-04-14 118 views
1

我想刪除table participant_vote中id與另一個錶行的id相匹配的所有記錄。刪除多行

這可以在一個查詢中完成嗎?

這是查詢我現在已經返回錯誤,我再選擇包含多個行

DELETE FROM participant_vote WHERE ID =(SELECT ID FROM vote WHERE facebookid =:facebookid)

回答

2
DELETE FROM participant_vote WHERE id IN (SELECT id FROM vote WHERE facebookid = :facebookid) 

IN是的伎倆。我的感覺是,尋找信息也會提供一個答案。

2

是的。使用IN運算符而不是=運算符。

DELETE FROM participant_vote 
WHERE id IN (
    SELECT id 
    FROM vote 
    WHERE facebookid = :facebookid 
)