开发者

get duplicated value in records

开发者 https://www.devze.com 2023-01-19 10:24 出处:网络
i have some 开发者_如何学Pythonrecords in a table. some of them have duplicated value in a field.

i have some 开发者_如何学Pythonrecords 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消