Delete duplicate rows using Analytical functions

Jeby Sebastian picture Jeby Sebastian · Mar 18, 2013 · Viewed 23.5k times · Source

Can we delete duplicate rows using analytical functions? I mean using row_number() or rank or dense_rank() in Sql query in Oracle?

Answer

JWK picture JWK · Mar 18, 2013

You can use ROW_NUMBER() over a partition of columns that should be unique for you, e.g: ROW_NUMBER() OVER (PARTITION BY COLUMN1, COLUMN2 ORDER BY COLUMN1). Every result that has a rownumber > 1 is a duplicate.

You can then for example return the rowid's for those and delete them.