How to find duplicate records in MySQL query


In MySQL find the Find the duplicate records by using COUNT function

SELECT * FROM employee;

    id  name    salary  
------  ------  --------
     1  Ramesh      5000
     2  Ashish      4000
     3  Rahul       6000
     4  Vishal      7000
     5  Harsh       3000
     6  Kamal       1000
     7  Kamal        500

Get the duplicate records in MySQL

SELECT `name`,COUNT(*) AS total FROM `employee` GROUP BY `name` HAVING COUNT(`name`)>1;
# OR
SELECT `name`,count(*) as total FROM `employee` GROUP BY `name` having total>1;

Output ::

name     total  
------  --------
Kamal          2

Find the duplicate recods by multiple columns in MySQL query

SELECT ColumnA, ColumnB, ColumnC, count(*) as total 
from table 
group by ColumnA, ColumnB, ColumnC 
having total > 1;


Related

find the nth highest salary in mysql without limit
How to find greater than average salary records in MySQL
How to use second index forcefully in MySQL
How to get total number of rows in MySQL table with and without count
Difference between where and having clauses