home go links go books go opinion go gallery go projects go resumé go
about this site
archives
book reviews
"to read" list
tech books
search books
books archive
last 10 posts
quotes
cluetrain
cluetrain (mirrored)
randobracket
image auth
search engine hits
  hit history
indexer stats
user agent list
HTML (view)
  (most up-to-date)
MS Word (dl)
code examples
doesntsuck.com
doesntsuck.com

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
);

Posted by yargevad at June 9, 2004 04:15 PM


This weblog is licensed under a Creative Commons License.