How to find duplicate row in a table - MSSQL

The below given query will fetch the duplicate rows in MSSQL with number of occurance of each row.

SELECT     <all column names - comma seperated>, COUNT(<name of any one column>) AS Occurance_Count
FROM <table name>
GROUP BY <all column names - comma seperated>
HAVING (COUNT(<name of any one column>) > 1)

 

Note: The data in '<>' should be replaced with relevent data. E.g. '<all column namesĀ - comma seperated>' should be replaced with 'a,b,c' where a, b and c are the names of the columns in the table.

3
Your rating: None Average: 3 (1 vote)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)