1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断。
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录。
3、查找表中多余的重复记录(多个字段)。
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录。
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录。就完成了。
Oracle 删除重复数据只留一条
查询及删除重复记录的SQL语句
1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断
select * from 表 where Id in (select Id from 表 group byId having count(Id) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表 GROUP BY id HAVING COUNT(*) > 1);
3、查找表中多余的重复记录(多个字段)
select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
oracle中在一张表中某个字段下面有重复记录,有很多方法,但是有一个方法,是比较"高效"的,如下语句:
SELECT data_guid
FROM adam_entity_datas a
WHERE a.rowid > (SELECT MIN(b.rowid)
FROM adam_entity_datas b
WHERE b.data_guid = a.data_guid)
如果表中有大量数据,但是"重复数据比较少",那么可以用下面的语句提高效率
SELECT data_guid
FROM adam_entity_datas
WHERE data_guid IN (SELECT data_guid
FROM adam_entity_datas
GROUP BY data_guid
HAVING COUNT(*) > 1)
此方法查询出所有重复记录了,也就是说,只要是重复的就选出来,下面的语句也许"更高效"
SELECT data_guid
FROM adam_entity_datas
WHERE ROWID IN (SELECT rid
FROM (SELECT ROWID rid,
row_number() over(PARTITION BY data_guid ORDER BY ROWID) m
FROM adam_entity_datas)
WHERE m <> 1)
不能直接选出来删,直接delete会把所有重复的ID全部干掉
create table xxx as
select distinct ID、NAME、DIANHUA、DIZHI from z
delete from z t where t.rowid not in (select min(rowid) from z t1 where t1.id=t.id group by id)