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: query help wanted

Re: query help wanted

From: Tim Witort <trwAT_at_ATmedicalert.DOTorg>
Date: 1997/07/10
Message-ID: <33C57F96.7CD9@ATmedicalert.DOTorg>#1/1

TommCarr wrote:
>
> > I need some help/suggestions for a query that will keep the 200 most
 current rows
> > for each customer and delete the rest (older) ones.
> >
> > Table contains 2 columns - custid, access_date
> >
> > For each custid, keep the 1st 200 most current rows, rest to be deleted.
>
> Simple:
>
> delete from cust
> where rowid not in(
> select rowid from cust
> where rownum <= 200
> order by access_date desc);

This will delete all but the 200 most recent rows in the whole table - not for each customer. But this delete statement is still usable for the problem by including the customer id.

Received on Thu Jul 10 1997 - 00:00:00 CDT

Original text of this message

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