Cudos
Cudos

Reputation: 5894

Find duplicate strings in database

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.

Upvotes: 6

Views: 5414

Answers (2)

devrooms
devrooms

Reputation: 3149

Yes, using GROUP BY and HAVING.

SELECT mycolumn, count(*) FROM mytable
group by mycolumn
having count(*) > 1

Upvotes: 5

Richard Fawcett
Richard Fawcett

Reputation: 2809

Yes, try something like this:

SELECT *
FROM `YourTable`
WHERE `YourColumn` IN (
    SELECT `YourColumn`
    FROM `YourTable`
    GROUP BY `YourColumn`
    HAVING COUNT(*) > 1
)

Upvotes: 8

Related Questions