Pages

Tuesday, March 9, 2010

Count Duplicate Records – Rows

How to find count of all the duplicate records in the table.
Following query demonstrates usage of GROUP BY, HAVING, ORDER BY in one query and returns the results with duplicate column and its count in descending order.

-- Count Duplicate Records from Table

SELECT YourColumn, COUNT(*) TotalCount
FROM YourTable
GROUP BY YourColumn
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC


0 comments:

Post a Comment