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

Home -> Community -> Usenet -> c.d.o.server -> Re: Finding Duplicates

Re: Finding Duplicates

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Sun, 13 Feb 2005 08:21:37 +0100
Message-ID: <420effd8$0$488$626a14ce@news.free.fr>

"Rishi Pahuja" <rishipahuja_at_rediffmail.com> a écrit dans le message de news:1108237613.526713.11620_at_f14g2000cwb.googlegroups.com...
| Hello Everyone,
|
| If any one can help me to write a query to delete duplicates from a
| table using 'analytic functions' it will be helpful.
|
| All I want is to keep two records from a set of duplicates the most
| oldest and most recent one.
|
| Eg:
| 1. X Y Z 10/2/2004
| 2. X Y Z 10/3/2004
| 3. X Y Z 10/4/2004
|
| Output should be rows returned for 1 and last entry.
|
| I want to achieve this with one query and not a PL-SQL code. Also the
| table I fire query will be 100M + records.
|
| Thanks in advance.
|
| Rishi
|

To get the most recent and oldest one per col1, col2, col3:

select col1,col2,col3,coldate from
(select col1,col2,col3,coldate,
rank() over(partition by col1,col2,col3 order by coldate) r1, rank() over(partition by col1,col2,col3 order by coldate desc) r2 from t)
where r1=1 or r2=1
/

Regards
Michel Cadot Received on Sun Feb 13 2005 - 01:21:37 CST

Original text of this message

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