oracle删除重复行的方法

删除重复行有两种方法:

数据准备
建表语句
create table a(a varchar2(10),b varchar2(20));
插入数据
insert into a values('11','22');
insert into a values('11','22');
insert into a values('11','22');
insert into a values('aa','bb');
insert into a values('aa','bb');
insert into a values('cc','dd');
commit;

 

克隆一张表
create table test  as (select * from a);
查询(1)select * from test
1 11 22
2 11 22
3 11 22
4 aa bb
5 aa bb
6 cc dd
(2)
select distinct * from test;
1 11 22
2 cc dd
3 aa bb

  

1)利用中间表法:create table test_copy as (select distinct * from test);

然后删除原表 drop table test;

create table test as (select  * from test_copy);

然后就完成了。

2)利用rowid法

sql语句如下:

delete from test t where rowid not in(
select max(rowid) from test p  where t.a=p.a and t.b=p.b);
commit;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值