Skip to content

Instantly share code, notes, and snippets.

@iainelder
Created June 23, 2014 22:22
Show Gist options
  • Save iainelder/a402fec91b56b59780ab to your computer and use it in GitHub Desktop.
Save iainelder/a402fec91b56b59780ab to your computer and use it in GitHub Desktop.
# T-SQL doesn't support the INTERSECT ALL operator.
# This gets you close.
# It only returns just one copy of each duplicate.
# GROUP BY * is not valid syntax so you have to write all the column names out.
SELECT *
FROM (
SELECT *
FROM #HasDupes
UNION ALL
SELECT DISTINCT *
FROM #HasDupes
) AS allrows
GROUP BY <all columns>
HAVING COUNT(*) > 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment