Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite: Delete results from SELECT with EXCEPT

Tags:

sqlite

I've got two tables, Feeds and Import in an SQLite DB. I'm pulling all enclosures from a list of rss feeds into the Import table; most of which are in the Feeds table as well. I'm trying to delete the records from the Feeds table where the enclosures are not in the Import table because they are no longer in the rssfeeds and they've been downloaded. Basically this is my setup:

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)

I'm probably over thinking this and making it way more complicated than it really is.

like image 613
MRR0GERS Avatar asked Mar 03 '26 16:03

MRR0GERS


1 Answers

DELETE
  FROM Feeds
 WHERE downloaded = 1
   AND NOT EXISTS (
          SELECT *
            FROM Import b
           WHERE Feeds.id = b.id
             AND Feeds.url = b.url )
like image 87
dcp Avatar answered Mar 06 '26 01:03

dcp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!