Wednesday, September 21, 2011

How to find duplicate rows in a table in SQL Server

To demonstrate this, I have a table with 2 duplicate rows as shown in the figure below:

And here is the query you can use to find out duplicate rows:
SELECT ProductID, ProductName, ProductNumber, Cost, NumberOfDuplicateRows=count(*)
FROM dbo.Product
GROUP BY ProductID, ProductName, ProductNumber,Cost
HAVING count(*) > 1

No comments:

Post a Comment