我在SQLite数据库中有两个表,Feeds和Import。我将rss feed列表中的所有附件都放入Import表中;其中大部分都在Feeds表中。我正在尝试从“源”表中删除记录,其中磁盘不在“导入”表中,因为它们不再位于rssfeeds中并且已经下载。基本上这是我的设置:
TABLE Feeds
id (TEXT)
url (TEXT)
downloaded (BIT)
TABLE Import
id (TEXT)
url (TEXT)
# results to delete
(SELECT id,url FROM Feeds WHERE downloaded = 1 EXCEPT SELECT id,url FROM Import)
我可能会过度思考这个问题并使其变得比实际情况更复杂。
答案 0 :(得分:5)
DELETE
FROM Feeds
WHERE downloaded = 1
AND NOT EXISTS (
SELECT *
FROM Import b
WHERE Feeds.id = b.id
AND Feeds.url = b.url )
答案 1 :(得分:0)
DELETE
FROM Feeds
WHERE downloaded = 1
AND NOT EXISTS (SELECT 1 FROM Import WHERE id = Feeds.id AND url = Feeds.url)