Skip to content

Instantly share code, notes, and snippets.

@geo-stanciu
Created March 27, 2019 13:39
Show Gist options
  • Save geo-stanciu/44ba722af2c19b722a68ac70176749e0 to your computer and use it in GitHub Desktop.
Save geo-stanciu/44ba722af2c19b722a68ac70176749e0 to your computer and use it in GitHub Desktop.
Clear Duplicate Rows
psql -d devel
-- delete duplicate rss - postgresql
DELETE FROM rss T1
USING rss T2
WHERE T1.ctid < T2.ctid
AND T1.rss_source_id = T2.rss_source_id
AND T1.title = T2.title
AND T1.link = T2.link;
\q
mysql devel
-- delete duplicate rss - mysql
DELETE T1 FROM rss T1
INNER JOIN rss T2
WHERE T1.rss_id < T2.rss_id
AND T1.rss_source_id = T2.rss_source_id
AND T1.title = T2.title
AND T1.link = T2.link;
\q
sqlcmd -d devel
-- duplicate rss - sql server
WITH r AS (
SELECT ROW_NUMBER() OVER(PARTITION by rss_source_id, title, link ORDER BY rss_id DESC) AS row
FROM rss
)
DELETE FROM r
WHERE row > 1;
go
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment