SQL重复记录查询和删除方法
作者:网络转载 发布时间:[ 2016/11/28 13:21:41 ] 推荐标签:SQL Server 数据库
MYSQL 查询和删除重复记录的方法很多,下面为您介绍几种常用的 MYSQL 查询和删除重复记录的方法,希望对您查询和删除重复数据方面能有所帮助。
SQL重复记录查询的几种方法:
1. 查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId
in (select peopleId from people
group by peopleId
having count(peopleId) > 1)
2. 删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有 rowid 小的记录
delete from people
where peopleId
in (select peopleId from people
group by peopleId
having count(peopleId) > 1)
and rowid not in (
select min(rowid) from people
group by peopleId
having count(peopleId)>1)
3. 查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq)
in (select peopleId,seq from vitae
group by peopleId,seq
having count(*) > 1)
4. 删除表中多余的重复记录(多个字段),只留有 rowid 小的记录
delete from vitae a
where (a.peopleId,a.seq)
in (select peopleId,seq from vitae
group by peopleId,seq
having count(*) > 1)
and rowid not in (
select min(rowid) from vitae
group by peopleId,seq having count(*)>1)
5. 查找表中多余的重复记录(多个字段),不包含 rowid 小的记录
select * from vitae a
where (a.peopleId,a.seq)
in (select peopleId,seq from vitae
group by peopleId,seq
having count(*) > 1)
and rowid not in (
select min(rowid) from vitae
group by peopleId,seq
having count(*)>1)
以上 SQL 记录重复数据查询和删除方法,希望能够帮助你。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11