当前位置:   article > 正文

Mysql数据库中根据某个或多个字段查询重复数据的sql语句_数据库查重语句怎么写

数据库查重语句怎么写

Mysql数据库中根据某个或多个字段查询重复数据的sql语句

sql 查出一张表中重复的所有记录数据

1.表中有id和name 两个字段,查询出name重复的所有数据

select * from xi a where (a.username) in (select username from xi group by username having count(*) > 1)

2、查询出所有数据进行分组之后,和重复数据的重复次数的查询数据,先列下:

select count(username) as ‘重复次数’,username from xi group by username having count(*)>1 order by username desc

3、查找表中多余的重复记录,重复记录是根据单个字段(openid)来判断

SELECT * FROM weixin_user where openid in ( select openid from weixin_user group by openid having count(*) > 1)

4、查找表中多余的重复记录(多个字段:openid,nickname)

SELECT * FROM weixin_user where (openid,nickname) in ( select openid,nickname from weixin_user group by openid,nickname having count(*) > 1)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/741801
推荐阅读
相关标签
  

闽ICP备14008679号