Showing posts with label Identify Duplicate records in SQL Server 2005. Show all posts
Showing posts with label Identify Duplicate records in SQL Server 2005. Show all posts

Thursday, February 25, 2010

Identify Duplicate records in SQL Server 2005

We are having large data base and it's having vast records for example we have 10 millins of records in a data abse then we will find what are all the duplicates records based some sriteria. following is the example query.

Query:
SELECT au_lname, au_fname, city, state, RecCount=COUNT(*), PktoKeep = MAX(NewPK)
INTO #DUPLICATES
FROM dup_authors
GROUP BY au_lname, au_fname, city, state
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC, au_lname, au_fname

'INTO' is a clause it inserts the selection data in to 'DUPLICATES' temporary table.