删除重复行有两种方法:
数据准备
建表语句
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;