Removing duplicate rows from table in Oracle

前端 未结 22 1591
醉话见心
醉话见心 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:25

    From Ask Tom

    delete from t
     where rowid IN ( select rid
                        from (select rowid rid, 
                                     row_number() over (partition by 
                             companyid, agentid, class , status, terminationdate
                                       order by rowid) rn
                                from t)
                       where rn <> 1);
    

    (fixed the missing parenthesis)

提交回复
热议问题