SQL Server - Identify Duplicates in a field
This SQL Query identifies the
duplicate names in a table. In the below
example, there are 2 persons with the same name “Rakesh” in the system. This query using the group by and having clause
identifies those names.
select
EmpName, count(1) DuplicateCount
from
Employee
group by
EmpName
having count(1) > 1
Input
|
EmpNo |
EmpName |
|
1001 |
Rakesh |
|
1002 |
Aneesh |
|
1003 |
Sravan |
|
1004 |
Rakesh |
Output
|
EmpName |
DuplicateCount |
|
Rakesh |
2 |
Comments
Post a Comment