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: When duplicate delete oldest date and if equal delete either?

Re: When duplicate delete oldest date and if equal delete either?

From: DA Morgan <damorgan_at_psoug.org>
Date: Fri, 14 Sep 2007 08:38:00 -0700
Message-ID: <1189784271.786199@bubbleator.drizzle.com>


jobs wrote:
> select * from tmp_autorecharge_work a where exists
> (select l.account_number from tmp_autorecharge_work l where
> a.account_number = l.account_number
> group by l.account_number having count(*) > 1)
> and a.last_update = (select min(b.last_update) from
> tmp_autorecharge_work b where b.account_number = a.account_number)
>
> The above logic does list the older record, problem is in some cases
> there are two or more older records with the same date.
>
> Basically I only want to leave the most recent row in the table, if
> there are two rows with the same last_update, remove the first in. The
> above is a select I planned to turn into a delete statement.
>
> thanks for any help or information.

Given the column names my first thought is that this is an accounting application and you should never delete records.

Reconsider your approach. Add an additional column and updated it to flag the most recent record.

-- 
Daniel A. Morgan
University of Washington
damorgan_at_x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Received on Fri Sep 14 2007 - 10:38:00 CDT

Original text of this message

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