Friday, 18 October 2013

SQL SERVER – Count Duplicate Records – Rows




SQL SERVER – Count Duplicate Records – Rows


In my previous article SQL SERVER – Delete Duplicate Records – Rows, we have seen how we can delete all the duplicate records in one simple query. In this article we will see 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.


SELECT YourColumn, COUNT(*) TotalCountFROM YourTable 
GROUP BY YourColumnHAVING COUNT(*) > 1 
ORDER BY COUNT(*) DESC

No comments:

Post a Comment

SQL SERVER – Disk Space Monitoring – Detecting Low Disk Space on Server

CREATE PROCEDURE [CSMSDVLP].[DiskSpaceMonitor] @mailProfile nvarchar(500), @mailto nvarchar(4000), @threshold INT, @logfile nvarchar(40...