Skip to content

Instantly share code, notes, and snippets.

@everettcaleb
Last active January 20, 2016 14:24
Show Gist options
  • Save everettcaleb/a67891941b2b60c8f2dc to your computer and use it in GitHub Desktop.
Save everettcaleb/a67891941b2b60c8f2dc to your computer and use it in GitHub Desktop.
Finds duplicate records in a table
;WITH [CTE] AS (
SELECT
[Field],
COUNT(1) AS [Count]
FROM [dbo].[Table]
GROUP BY [Field]
)
SELECT [T].[Field]
FROM [Table] [T]
INNER JOIN [CTE] ON [T].[Field] = [CTE].[Field]
WHERE [CTE].[Count] > 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment