⑴ 如何查找和删除数据库中的重复数据
法一: 用Group by语句 此查找很快的select count(num), max(name) from student –查找表中num列重复的,列出重复的记录数,并列出他的name属性group by numhaving count(num) >;1 –按num分组后找出表中num列重复,即出现次数大于一次delete from student(上面Select的)这样的话就把所有重复的都删除了。—–慎重法二:当表比较大(例如10万条以上)时,这个方法的效率之差令人无法忍受,需要另想办法:—- 执行下面SQL语句后就可以显示所有DRAWING和DSNO相同且重复的记录SELECT * FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB D –D相当于First,SecondWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO);—- 执行下面SQL语句后就可以删除所有DRAWING和DSNO相同且重复的记录DELETE FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB DWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO);法一: 用Group by语句 此查找很快的select count(num), max(name) from student –查找表中num列重复的,列出重复的记录数,并列出他的name属性group by numhaving count(num) >;1 –按num分组后找出表中num列重复,即出现次数大于一次delete from student(上面Select的)这样的话就把所有重复的都删除了。—–慎重法二:当表比较大(例如10万条以上)时,这个方法的效率之差令人无法忍受,需要另想办法:—- 执行下面SQL语句后就可以显示所有DRAWING和DSNO相同且重复的记录SELECT * FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB D –D相当于First,SecondWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO);—- 执行下面SQL语句后就可以删除所有DRAWING和DSNO相同且重复的记录DELETE FROM EM5_PIPE_PREFABWHERE ROWID!=(SELECT MAX(ROWID) FROM EM5_PIPE_PREFAB DWHERE EM5_PIPE_PREFAB.DRAWING=D.DRAWING ANDEM5_PIPE_PREFAB.DSNO=D.DSNO);
⑵ 如何查找数据库中的重复数据
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from peoplewhere peopleId in (select peopleId from people group by peopleId having count (peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from peoplewhere 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 awhere (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
(2)如何用c语言找重复的数据库扩展阅读
FROM子句指定SELECT语句查询及与查凳凯询相关的表或视图。在FROM子句中最多可指定256个表或视图,它们之间用逗号分隔。
在FROM子句同时指定多个表或视图时,如果选择列表中存在同名列,这时应使用对象名限定这些列所属的表或视图。
例如在usertable和citytable表中同时存在cityid列,在查询两个表中的cityid时应使用下面语句格式加以限定:
SELECTusername,citytable.cityid
FROMusertable,citytable
WHEREusertable.cityid=citytable.cityid
在FROM子句中可用以下两种格式为表或视图指定别名:
表名 as 别名
表名 别名
参考资蔽让料:百枣并唤度网络 SELECT语句
⑶ 如何查找数据库中的重复数据
实现方式如下:
1。删除全部重复记录(慎用)
Delete表Where重复字段In(Select重复字段From表GroupBy重复字段HavingCount(*)>1)
2。保留一条(这个应该是大多数人所需要的^_^)
DeleteHZTWhereIDNotIn(SelectMax(ID)FromHZTGroupByTitle)
注:此处保留ID最大一条记录
3、查找表中多余的重复记录(多个字段)
select*fromvitaea
where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhavingcount(*)>1)4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
deletefromvitaea
where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhavingcount(*)>1)
androwidnotin(selectmin(rowid)fromvitaegroupbypeopleId,seqhavingcount(*)>1)