Monday, January 21, 2013

SQL: Finding Duplicate Reocrds

SELECT Col_1,
 COUNT(Col_1) AS NumOccurrences
FROM Table_Name
GROUP BY Col_1
HAVING ( COUNT(Col_1) > 1 );

SELECT COUNT(*) FROM Table_1;
vs.
SELECT DISTINCT(COUNT(*)) FROM Table_1;

If the different between these two counts are different, then you have an idea how many records are duplicate. Unfortunately, I have not found an easy way to populate duplicates side by side. Please comment if anyone has a better way.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.