Tuesday, August 11, 2009

How to View or display Duplicate Rows in SQL?

Following code is useful to View / Display duplicate records. The table must have identity column, which will be used to identify the duplicate records. Table in example is has ID as Identity Column and Column which have duplicate data is Column1

SELECT Column1, COUNT(*) TotalCount

FROM MyTable

GROUP BY Column1

HAVING COUNT(*) > 1

ORDER BY COUNT(*) DESC

 

 

No comments:

Post a Comment