Profile

Sunday 29 May 2011

SQL: Look for duplicated record within a table.

How to spot a duplicated record in a table? One way to slide it is to let SQL query to group the identical records then count how many identical record exist in a table:  

       SELECT * FROM(
       SELECT COUNT(*) num,  PARTSNNU, PARTMADEIN, PARTNAME
       FROM [DB-DWH].[dbo].[PART]
       GROUP BY  PARTSNNU, PARTMADEIN, PARTNAME ) a
       WHERE  num>1

If the table has no duplicated record, there will be no record returns on the result set.