高分求救?如何查看和删除表中重复数据?
有一个表导数据时导入了重复的数据,现在家主键家不上啊,如何查看和删除!
在线求救!!
------解决方案----------------------全部重复:
select distinct * into #temp from 表
truncate table 表
insert 表 select * from #temp
drop table #temp
------解决方案--------------------有一个表导数据时导入了重复的数据,现在家主键家不上啊,如何查看和删除!
在线求救!!
如果ID为主键,且有列col可按ID区分大小.
--查询
select * from tb where id in (select id from tb group by id having count(*) > 1)
--删除
delete from tb where col not in (select min(col) from tb group by id )
------解决方案--------------------在几千条记录里,存在着些相同的记录,如何能用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)
------解决方案--------------------学习了
------解决方案--------------------如果ID为主键,且有列col可按ID区分大小.
是什么意思啊
就是说主键ID重复的值,有一个其他列(col)可区分其大小,这样可以在删除时留住最大(或最小)的那行.如果所有列都不能区分大小,则只有使用临时表了.
如
id col id col
1 1 1 1
1 1 1 2
1 2 1 3
2 1 2 1
2 2 2 2
2 3 3 1
------解决方案--------------------查有重复记录的。
select col1,col2,col3 from tablename group by col1,col2,col3 having count(*)> 1