如何删除表中重复的行?

来源:互联网 发布:360度拍摄软件 编辑:程序博客网 时间:2024/05/20 09:26

思路:记录虽然存在重复,但是rowid是唯一的,所以在子查询取得重复行中最小的rowid,删除重复行中
大于最小的rowid的行,只是保留了最小rowid的行,就是删除了重复行。
这个语句如果要调优的话,可以在内部查询中建索引。

SQL> select * from ttt;
NAME
--------------------

ab
ab
cd
cd
ef


SQL> delete from ttt a where rowid>(select min(rowid) from ttt b where a.name=b.name);


2 rows deleted.
SQL> select * from ttt;
NAME
--------------------

ab
cd
ef

原创粉丝点击