Skip to content

Instantly share code, notes, and snippets.

@Mpdreamz
Created June 28, 2012 07:55
Show Gist options
  • Save Mpdreamz/3009771 to your computer and use it in GitHub Desktop.
Save Mpdreamz/3009771 to your computer and use it in GitHub Desktop.
Dedup CTE awesomeness
WITH CTE (Colum1, Colum2, DuplicateCount)
AS
(
SELECT Colum1, Colum2, ROW_NUMBER()
OVER(PARTITION BY Colum1, Colum2 ORDER BY Colum1) AS DuplicateCount
FROM MyTable
WHERE Colum1 = 1 AND Colum2 IS NOT NULL
)
SELECT * FROM CTE
WHERE DuplicateCount > 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment