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: Help: Delete all rows except 1 of a set of rows.

Re: Help: Delete all rows except 1 of a set of rows.

From: Rich W. <rwerning_at_execpc.com>
Date: Thu, 17 Sep 1998 08:32:38 -0500
Message-ID: <36010f05.0@tornado.tcccom.net>

Thomas Kyte wrote in message <360afe55.95405355_at_192.86.155.100>... <Snip>
>>In a nutshell, there should of been a unique key assigned to a table, but
>>there wasn't. I need to clean up the table and create a new unique key
when
>>done.
>>
>>I can find all of the rows that have duplicates using:
>>
>>SQL> select risn, crit_code, crit_rev from ri_result group by risn,
>>crit_code, crit_rev having count(*) > 1;
>>
>>I just don't know how to do the delete, leaving 1 row of each.
>>
>>Thanks for any help,
>> Rich W.
>>
>
>if you want to just delete dups, leaving a 'random' one of them behind, the
>following delete will do it:
>
>delete from ri_result
>where rowid <> ( select max(rowid)
> from ri_result b
> where b.risn = ri_result.risn
> and b.crit_code = ri_result.crit_code
> and b.crit_rev = ri_result.crit_rev )
>/

<Snip>
>Thomas Kyte
>tkyte_at_us.oracle.com
>Oracle Government
>Herndon VA

This was exactly what I was looking for, it worked fine. Thanks alot for the help.

Received on Thu Sep 17 1998 - 08:32:38 CDT

Original text of this message

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