Write a Query to select duplicate records in the database table.
Example:
Employee Table;ID Name Department1 Sumit IT2 Rohan IT3 Sumit ME4 Rohan ME5 Sumit ME6 Raja IT
Approach :
Mysql
Find Duplicate based on Name
Query: select Name, count(1) countfrom Employee group by Namehaving count>1;Output :Name CountSumit 3Rohan 2
Find Duplicate based on Name and Department
Query: select Name, Department, count(1) countfrom Employee group by Name, Departmenthaving c>1;Output :Name Department CountSumit ME 2
No comments:
Post a Comment