比较2列和删除不匹配

时间:2012-04-11 23:10:22

标签: php mysql

$db->query("DELETE FROM   probid_auction_media 
WHERE auction_id NOT IN SELECT DISTINCT auction_id FROM probid_auctions");

这是我正在使用的代码,我想要做的是将probid_auction_media的专栏auction_id与probid_auctions的专栏auction_id进行比较,并从probid_auction_media中删除任何不算数学的专栏

2 个答案:

答案 0 :(得分:0)

你需要括号:

DELETE FROM   probid_auction_media 
WHERE auction_id NOT IN 
      ( SELECT auction_id FROM probid_auctions )

答案 1 :(得分:0)

你错过了括号。此外,DISTINCT可能不是必需的:

DELETE FROM probid_auction_media
    WHERE auction_id NOT IN (SELECT auction_id FROM probid_auction)