Skip to content

Instantly share code, notes, and snippets.

@markmo
Created March 19, 2013 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmo/5193259 to your computer and use it in GitHub Desktop.
Save markmo/5193259 to your computer and use it in GitHub Desktop.
Recreate dups
INSERT INTO X (...)
SELECT ...
FROM (
SELECT <group by keys>, COUNT(*) - 1 AS K
FROM <table with dups>
WHERE ...
GROUP BY <group by keys>
HAVING COUNT(*) > 1
) A
JOIN Tally on Tally.N <= A.K
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment