欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【数据库】小例子Oracle删除重复数据

程序员文章站 2022-06-02 16:42:39
...

【数据库】Oracle删除重复数据

如下,数据表结构

id name pass
1 aaa 111
2 bbb 222
3 ccc 333

通过SQL,完成如下效果:

id name pass
1 aaa 111
2 bbb 222
3 ccc 333
1 aaa 111
2 bbb 222
3 ccc 333

实现SQL:

insert into test_001 (id,name,pass) select id,name,pass from test_001 ;
 commit;

删除重复数据

delete from test_001 where name in (select name from test_001 group by name having count(name)>1)
and rowid not in (select min(rowid) from test_001 group by name having count(name)>1) ;
commit;