刪除重複行有兩種方法:
數據準備
建表語句
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;