Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: DELETING DUPLICATE ROWS

Re: DELETING DUPLICATE ROWS

From: Chuck Hamilton <chuckh_at_dvol.com>
Date: 1997/05/30
Message-ID: <3390c52c.625321@news.dvol.com>#1/1

smantri_at_site.gmu.edu (Shiva K Mantri (CS)) wrote:

>Hi Everybody,
>
>Can any one tell me how to delete duplicate rows in a table?
>
> 1) the rows are duplicate by primary key.
>
>I need to delete all the rows identical row values
>
>------Shiva Mantri

Do you want to leave one of the rows intact and just delete the duplicates? Below is a script I use to do that. I not only deletes duplicates, but leaves an audit trail of the duplicate pk_values.

accept tabnam prompt 'Enter table name to dedupe: ' accept pk_cols prompt 'Enter primary key columns separated by commas: '

set verify off

drop table dedupe$
/
create table dedupe$
as (select '&&tabnam' table_name, &&pk_cols, min(rowid) min_rowid

    from &&tabnam
    group by &&pk_cols
    having count(*) > 1)
/
delete from &&tabnam
where (&&pk_cols) in (select &&pk_cols from dedupe$) and rowid not in (select min_rowid from dedupe$) /

--
Chuck Hamilton
chuckh_at_dvol.com

Never share a foxhole with anyone braver than yourself!
Received on Fri May 30 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US