Tuesday, January 10, 2012

How to remove the duplicate rows from table in Oracle


we can easily remove the duplicate rows because by default oracle maintain the unique rowid for each row.
Here is the syntax to remove the duplicate rows

DELETE FROM <tablename>
      WHERE ROWID NOT IN (  SELECT MAX (ROWID)
                          FROM <tablename>
                      GROUP BY column1, column2,...)

You should use group by all columns then only you can get the exact duplicate rows and you can use both MAX(rowid) or MIN(rowid).

I hope this article will be very helpful to all. Thanks for reading this article.

“Keep reading and share the knowledge”  
“Grow more trees to save Earth”

No comments:

Post a Comment