Removing duplicate rows from table in Oracle

前端 未结 22 1758
醉话见心
醉话见心 2020-11-22 12:57

I\'m testing something in Oracle and populated a table with some sample data, but in the process I accidentally loaded duplicate records, so now I can\'t create a primary ke

22条回答
  •  青春惊慌失措
    2020-11-22 13:37

    Using rowid-

    delete from emp
     where rowid not in
     (select max(rowid) from emp group by empno);
    

    Using self join-

    delete from emp e1
     where rowid not in
     (select max(rowid) from emp e2
     where e1.empno = e2.empno );
    

提交回复
热议问题