Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: query help wanted
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.
![]() |
![]() |