`
siashuayongsheng
  • 浏览: 118116 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

oracle删除重复的记录

    博客分类:
  • Java
阅读更多
delete from tbl where rowid in (select a.rowid from tbl a,
            tbl b where a.rowid>b.rowid and a.col1=b.col1 and a.col2 = b.col2)

delete from tbl awhere rowid not in (select max(b.rowid)
            from tbl b where a.col1=b.col1 and a.col2 = b.col2);
            //这里max使用min也可以

delete from tbl awhere rowid<(select max(b.rowid)
            from tbl b where a.col1=b.col1 and a.col2 = b.col2);
            //这里如果把max换成min的话,前面的where子句中需要把"<"改为">"

creat table tbl_tmp (select distinct* from tbl);truncate table tbl;
            //清空表记录insert into tbl select * from tbl_tmp;//将临时表中的数据插回来。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics