Oracle - deleting duplicates

后端 未结 2 1255
暗喜
暗喜 2021-01-28 10:55

I have found the following way for removing duplicates:

DELETE FROM
   table_name A
WHERE
  a.rowid >
   ANY (
     SELECT
        B.rowid
     FROM
        t         


        
相关标签:
2条回答
  • 2021-01-28 11:21

    In Oracle, ROWID is a pseudo column points to the physical location of a row. The query does a self join and fetches those rows which have the same value of column 1 & column 2 - with the assumption that these keys are enough to identify as duplicate row.

    Once the rows are fetched, the query then deletes those rowids which are larger than the first row fetched, thereby deleting duplicates

    0 讨论(0)
  • 2021-01-28 11:33

    Like this:

    DELETE FROM         // The command to delete
       table_name A     //the table in which you want to remove duplicate
    WHERE               //condition
      a.rowid >         //checking the rowid which oracle adds to each row. Oracle Database rowid values contain information necessary to locate a row.
       ANY (             //any row which has a condition
         SELECT          //select
            B.rowid      //rowid
         FROM             //from  
            table_name B    //table name with alias name as B. Is used for making a self join
         WHERE               //condition
            A.col1 = B.col1    //where the column1 has the same rowid 
         AND                    //and
            A.col2 = B.col2     //where the column2 has the same rowid 
            ); 
    
    0 讨论(0)
提交回复
热议问题