当前位置:首页 > 开发 > 数据库 > 正文

查询和删除表中重复数据sql语句(一)

发表于: 2013-03-22   作者:知了ing   来源:转载   浏览:
摘要: 1、查询表中重复数据。select * from people where peopleId in (select   peopleId   from   people   group   by   peopleId   having  
1、查询表中重复数据。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、查找表中多余的重复记录(多个字段)

elect * 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语句(一)

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号