Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql select ONLY duplicate records from database

Tags:

php

mysql

I'm trying to do something with the duplicate records in a mysql database. however, I don't want to delete the records, and only two columns are duplicate. How can I find just these records?

like image 866
Proffesor Avatar asked Mar 02 '12 22:03

Proffesor


1 Answers

can you post more information about the table structure and what do you mean that some are duplicate but only by two columns ?

Anyway, you can look into the GROUP BY, COUNT, and HAVING

SELECT `duped_field1`, `duped_field2`, COUNT(*) `tot`
FROM `table`
GROUP BY `duped_field1`, `duped_field2`
HAVING `tot` > 1
like image 182
Fabrizio Avatar answered Sep 29 '22 04:09

Fabrizio