Reputation: 18346
i have some records in a table. some of them have duplicated value in a field. i want to extract these duplicated values with mysql commands. how can i do that?
Upvotes: 1
Views: 53
Reputation: 18364
You mean something like: I have a Person table, and there are multiple person with the same name, I want to find them?
You can do that using a group by clause:
select p.name, count(p.name) c
from person p
group by p.name
having count(p.name) > 1
If you want to check duplicate multiple columns, then add all of them to the select
and group by
select p.name, p.age, p.sex, count(*) c
from person p
group by p.name, p.age, p.sex
having count(*) > 1
Upvotes: 2