Posted By

ezerick on 01/22/11


Tagged

database sql duplicates T-SQL


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

plugables


Find Duplicate Rows in Table


 / Published in: SQL
 

Field1 + Field2 + Field3 should create 1 entry for each unique row in the DB. In an employee table, this would be FirstName + LastName + EmployeeNumber

  1. SELECT * FROM TABLE WHERE field1 + field2 + field3 IN
  2. (
  3. SELECT field1 + field2 + field3 FROM TABLE GROUP BY field1 + field2 + field3 HAVING count(*) > 1
  4. )
  5. AND uniqueID NOT IN
  6. (
  7. SELECT MAX(uniqueID) FROM xer_regis_new GROUP BY field1 + field2 + field3 HAVING count(*) > 1
  8. )

Report this snippet  

You need to login to post a comment.