mysql查询重复的_mysql查询重复数据

本文介绍了如何在MySQL中查找和处理重复记录。提供了四种查询方法,包括查找特定字段重复的记录,以及在排除最小ID后的查询,适用于数据清洗和管理。
摘要由CSDN通过智能技术生成

表全部数据

49dc4390bb6e96c7c90fb01bb1d130b3.png

-------------------

1 查询people_no重复的记录

select * from people

where people_no in (select people_no from people group by people_no having count(people_no) > 1);

345d1954423fb49a57a3ab45ba00933c.png

----------------------

2 查询people_no重复的记录 ,排除最小id,如果删除改为delete from

select * from people

where people_no in (select people_no from people group by people_no having count(people_no) > 1) and

id not in (select min(id) from people group by people_no having count(people_no)>1);

1ba2cddd76808ca765698ba9abb42fcd.png

-----------------------------

3 查询people_no people_name重复的记录

select * from people a

where (a.people_no,a.people_name) in (select people_no,people_name from people GROUP BY people_no,people_name HAVING count(*)>1);

3517160de4ab390e5af053921ac79fd8.png

-----------------------------------

4 查询people_no people_name重复的记录,排除最小id

select * from people a

where (a.people_no,a.people_name) in (select people_no,people_name from people GROUP BY people_no,people_name HAVING count(*)>1) and

a.id not in (select min(id) from people GROUP BY people_no,people_name HAVING count(*)>1);

d58f10e7442b24f1689c4bde94fdf371.png

来源:https://www.cnblogs.com/LDDXFS/p/9867928.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值