我有两张表如下..
campaigns(campaignID, title)
campaignMailList(campaignID, Sent)
(2个表格更大..但为此我只需要这些列)
我想生成一个查询,该查询将删除campaignMailList中的所有行,而该行无法在campaignID上的广告系列表中找到联接。
有人可以建议我这样做吗?
答案 0 :(得分:2)
您可以尝试NOT IN
子句。
像
DELETE FROM `campaignMailList` as cml
WHERE cml.campaignid NOT IN ( SELECT campaignID FROM campaigns )
不确定这是否是最好的方法
答案 1 :(得分:2)
将您自己的问题逐字翻译成SQL:
delete from campaingMailList where
campaingId not in (select campaingid from campaigns)
答案 2 :(得分:1)
尝试此查询 -
DELETE cml FROM campaignMailList cml
LEFT JOIN campaigns c
ON c.campaignID = cml.campaignID
WHERE c.campaignID IS NULL