Select duplicate value in database table

Write a Query to select duplicate records in the database table.

Example:

Employee Table;
ID   Name    Department
1    Sumit   IT
2    Rohan   IT
3    Sumit   ME
4    Rohan   ME
5    Sumit   ME
6    Raja    IT

Approach : 

Mysql

Find Duplicate based on Name

Query: select Namecount(1) count 
from Employee group by Name 
having count>1

Output :
Name    Count
Sumit   3
Rohan   2

Find Duplicate based on Name and Department

Query: select Name, Department, count(1) count 
from Employee group by Name, Department 
having c>1;
 
Output :
Name    Department Count
Sumit   ME         2 


No comments:

Post a Comment