MYSQL加入查询不删除

时间:2015-10-29 00:28:51

标签: php mysql join

我试图通过id获取以下查询以删除所有行但是查询运行正常但它没有执行 - 没有错误或行受影响。我已经检查了表格中的所有coloumn名称并且它们是正确的。

MYSQL:

DELETE c FROM campaigns c 
JOIN campaignsFroms f ON f.campaign_id = c.id 
JOIN campaignsRaw r ON r.campaignId = c.id 
JOIN campaignsSubjects s ON s.campaign_id = c.id 
WHERE c.id = 1582

1 个答案:

答案 0 :(得分:1)

我想知道你是否想要这个:

DELETE c, f, r, s
FROM campaigns c LEFT JOIN
     campaignsFroms f
     ON f.campaign_id = c.id LEFT JOIN
     campaignsRaw r
     ON r.campaignId = c.id LEFT JOIN
     campaignsSubjects s
     ON s.campaign_id = c.id 
WHERE c.id = 1582;

这将删除与广告系列相关的所有表格中的记录。 LEFT JOIN是为了确保连接不会考虑这些行。