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)

猜你喜欢

转载自blog.csdn.net/guo_qiangqiang/article/details/87693322