Thursday, October 21, 2010

Find the duplicates and count of a column value in SQL Server

We have a table 'Test' with a column col1
Find the duplicate values & count of duplicates for the column col1


SELECT col1, COUNT(col1) AS NumOfOccurrences
FROM dbo.Test
GROUP BY col1
HAVING (COUNT(col1) > 1)

No comments:

Post a Comment