0

好的,所以我的问题是

我有一个支持自动上架的拍卖网站,但是当拍卖自动上架时,它不会清除旧条目,所以我打算编写一些 php 代码并将其作为 cronjob 运行以清除 2 天后的条目或因此,被引用的表是 probid_auctions 和 probid_auction_media 列是auction_id,我想将 probid_auction_media 中的auction_id 列与 probid_auctions 中的auction_id 列进行比较,并删除 probid_auction_media 中不匹配的任何条目

现在测试这个

mysql_connect($host, $username, $password);
mysql_select_db("b1396hos_database1") or die( "Unable to select database");
$db->query("DELETE * FROM  probid_auction_media 
WHERE auction_id NOT IN (SELECT DISTINCT auction_id FROM probid_auctions");
4

2 回答 2

1
DELETE FROM probid_auction_media 
WHERE auction_id NOT IN (SELECT DISTINCT auction_id FROM probid_auctions);
于 2012-04-11T21:49:15.133 回答
1

使用这样的查询

DELETE
FROM probid_auction_media
WHERE auction_id NOT IN(SELECT
                      probid_auction_media.auction_id
                    FROM probid_auctions,
                      probid_auction_media
                    where probid_auctions.auction_id != probid_auction_media.auction_id);
于 2012-04-12T06:21:11.623 回答