25 November 2015

Removing Duplicate Records In a table

Different Removes the duplicate Records from a table,

Option 1. By excluding the minimum row id from the group of duplicate records.

DELETE FROM test1
      WHERE ROWID NOT IN (  SELECT MIN (ROWID)
                              FROM test1
                          GROUP BY rc_no);


Option 2. Using row_number() option.

DELETE FROM test1
      WHERE ROWID IN (SELECT row_id
                        FROM (SELECT ROWID row_id,
                                     x,
                                     y,
                                     z,
                                     ROW_NUMBER ()
                                     OVER (PARTITION BY x, y, z ORDER BY x)
                                        rn
                                FROM test1)
                       WHERE rn > 1)

No comments: