Bkeshh Mhrjn Bkeshh Mhrjn - 5 months ago 18
MySQL Question

Find duplicate data in table using mysql

This my table structure :

id emp_id log_date
1 1 2015-1-1
2 1 2015-1-1
3 1 2015-1-2
4 2 2015-1-1
5 2 2015-1-2
6 2 2015-1-2


I want to pull duplicate
log_date
for every
emp_id
seperately.

Expected output:

id emp_id log_date
1 1 2015-1-1
2 1 2015-1-1
5 2 2015-1-2
6 2 2015-1-2

Answer

Try this;)

select t1.*
from yourtable t1
inner join (
    select emp_id, log_date from yourtable group by emp_id, log_date having count(*) > 1
) t2 on t2.emp_id = t1.emp_id and t2.log_date = t1.log_date

SQLFiddle DEMO HERE