June 09, 2004
oracle: remove duplicate rows (link)
http://www.remote-dba.cc/oracle_tips_duplicate_rows.htm
simple query to remove duplicate rows from an oracle table
The most effective way to detect duplicate rows is to join the table against itself as shown below.
SELECT
BOOK_UNIQUE_ID,
PAGE_SEQ_NBR,
IMAGE_KEY
FROM
page_image A
WHERE
rowid >
(SELECT min(rowid) FROM page_image B
WHERE
B.key1 = A.key1
and
B.key2 = A.key2
and
B.key3 = A.key3
);
Please note that you must specify all of the columns that make the row a duplicate in the SQL where clause. Once you have detected the duplicate rows, you may modify the SQL statement to remove the duplicates as shown below:
DELETE FROM
table_name A
WHERE
A.rowid >
ANY (SELECT B.rowid
FROM
table_name B
WHERE
A.col1 = B.col1
AND
A.col2 = B.col2
);