免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2995 | 回复: 0

几种查找和删除重复记录的方法 [复制链接]

论坛徽章:
0
发表于 2011-03-07 13:15 |显示全部楼层
几种查找和删除重复记录的方法




1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
  1. select * from people

  2. where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
复制代码
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录

  1. delete from people

  2. where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

  3. and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
复制代码
3、查找表中多余的重复记录(多个字段)
  1. select * from vitae a

  2. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
复制代码
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
  1. delete from vitae a

  2. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

  3. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
复制代码
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
  1. select * from vitae a

  2. where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

  3. and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP