Wednesday, March 17, 2010

how to query duplicate records in SQL

SELECT *
FROM Person.Address A
INNER JOIN (SELECT AddressLine1, City
FROM Person.[Address]
GROUP BY AddressLine1, City
HAVING COUNT(*) > 1) AS A1
ON A.AddressLine1 = A1.AddressLine1
AND A.City = A1.City
ORDER BY A.AddressLine1, A.City, A.AddressID

No comments: