Skip to content

Instantly share code, notes, and snippets.

@paradigm314
Last active December 19, 2017 16:47
Show Gist options
  • Save paradigm314/e9ddfaa18bd23e1d22e41b22abe4923b to your computer and use it in GitHub Desktop.
Save paradigm314/e9ddfaa18bd23e1d22e41b22abe4923b to your computer and use it in GitHub Desktop.
Remove Duplicates Postgres
/* Single Key Filter */
SELECT * FROM users
WHERE id IN (SELECT id
FROM (SELECT id, ROW_NUMBER()
OVER (PARTITION BY email ORDER BY id) AS rnum
FROM users) t
WHERE t.rnum > 1);
/* Multi Key Fileter */
SELECT * FROM theme_files
WHERE id IN (SELECT id
FROM (SELECT id, kind, ROW_NUMBER()
OVER (PARTITION BY theme_id, kind ORDER BY id) AS rnum
FROM theme_files) t
WHERE t.rnum > 1 AND t.kind = 'mobile_stylesheet');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment