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)

时间: 2024-10-24 01:57:28

Oracle 删除重复的记录,只保留一条的相关文章

【转】SQL删除重复记录,只保留其中一条

SQL:删除重复数据,只保留一条用SQL语句,删除掉重复项只保留一条在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(p

如何删除表中的重复记录只保留其中一条?

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  

MySQL删除重复记录只保留一条

删除表中重复记录,只保留一条: delete from 表名 where 字段ID in (select * from (select max(字段ID) from 表名 group by 重复的字段 having count(重复的字段) > 1) as b); 实例:2.当想要为某一个表建立一个唯一索引,由于表中有重复记录而无法进行时,需要删除重复记录.例表 dept id_no id_name 100 'AAA' 101 'BBB' 102 'CCC' 103 'DDD' 100 'EEE

160802、1.06s删除10w条重复记录只保留一条(mysql)及linux删除乱码文件

上次发表过的一遍删除重复记录的文章,其中最优的方案三删除1w条也花了0.07秒而2w条就已经花掉了4秒.今天进行了进一步优化,测试删除10w条只花了1.06秒.速度提升了很多. 建表语句 CREATE TABLE `test_user` ( `id` INT(10) NOT NULL DEFAULT '0', `namea` VARCHAR(40) NOT NULL, `nameb` VARCHAR(40) NOT NULL, `user_id` VARCHAR(40) NOT NULL, PR

SqlServer删除表中重复的记录并保留一条

--删除表 TableName 中字段 A.B.C 同时重复的数据,并保留一条 DELETE FROM dbo.TableName WHERE Id IN( --根据A,B,C三个字段查询出重复的数据 SELECT * FROM ( SELECT *,OrderNo=ROW_NUMBER() OVER(PARTITION BY A,B,C ORDER BY GETDATE()) FROM dbo.TableName ) Tmp WHERE OrderNo>1 );

MSSQL 删除重复并只保留一条

重复值查找 select field1,field2 from table group by field1,field2 having COUNT(*)>1 删除重复值,只保留ID最小的那条 delete table where field1 in (select field1 from VersionProductRelation a group by field1,field2 having COUNT(*)>1) and field2 in (select field2 from Ver

初探oracle删除重复记录,只保留rowid最小的记录

如题,初探oracle删除重复记录,只保留rowid最小的记录(rowid可以反映数据插入到数据库中的顺序) 一.删除重复记录可以使用多种方法,如下只是介绍了两种方法(exist和in两种). 1.首先创建一个测试表. create table my_users( id number, username varchar2(20), sal number ) 2.插入测试数据 begin for i in 1..10 loop insert into my_users values(i,'carl

oracle 删除掉重复数据只保留一条

用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有

Access数据库删除重复记录,只保留一条记录的做法

Access数据库删除重复记录,只保留一条记录的做法: 只保留id最小的记录方法: delete from [表名] where id not in (select min(id) from [表名] group by [带重复记录的字段名称]) 只保留id最大的记录方法: delete from [表名] where id not in (select max(id) from [表名] group by [带重复记录的字段名称])