Mysql Find Duplicate Records
Mysql Find Duplicate Records is used to find the duplicate Records in the table.
Understand with Example
The Tutorial illustrate an example from 'Mysql Find Duplicate Records'. To grasp and understand example, the select query is used to return the records from table 'employee12'.
select * from employee12; |
Table structure:
+-------+----------+--------+------------+ | Empid | Empname | Salary | DOB | +-------+----------+--------+------------+ | 1 | Habib | 2014 | 2004-12-02 | | 2 | Karan | 4021 | 2003-04-11 | | 3 | Samia | 22 | 2008-02-23 | | 4 | Hui Ling | 25 | 2008-10-15 | | 5 | Yumie | 29 | 1999-01-26 | | 10 | NULL | 210000 | 2009-01-12 | | 10 | jjlkl | 2222 | 2008-02-13 | | 10 | hkjkkjl | 2222 | 2008-02-14 | +-------+----------+--------+------------+ |
Query for finding duplicate records:
The Query is used to find the maximum number of duplicate records.
mysql> SELECT *, count(*) as n -> FROM employee12 -> group by empid -> HAVING n>1; |
Output:-
+-------+---------+--------+------------+---+ | Empid | Empname | Salary | DOB | n | +-------+---------+--------+------------+---+ | 10 | NULL | 210000 | 2009-01-12 | 3 | +-------+---------+--------+------------+---+ 1 row in set (0.00 sec) |