Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find duplicate strings in database

Tags:

sql

mysql

I need to find all rows in my table where the strings of a specific field are duplicates in two or more places.

Can that be done in a MySQL statment?

EDIT

I need to get every row not just a count of how many duplicates there are. I want to be able to edit the fields.

like image 439
Cudos Avatar asked Dec 10 '10 09:12

Cudos


2 Answers

Yes, try something like this:

SELECT *
FROM `YourTable`
WHERE `YourColumn` IN (
    SELECT `YourColumn`
    FROM `YourTable`
    GROUP BY `YourColumn`
    HAVING COUNT(*) > 1
)
like image 77
Richard Fawcett Avatar answered Sep 19 '22 01:09

Richard Fawcett


Yes, using GROUP BY and HAVING.

SELECT mycolumn, count(*) FROM mytable
group by mycolumn
having count(*) > 1
like image 33
devrooms Avatar answered Sep 20 '22 01:09

devrooms