Re: SQL*PLUS CHALLANGE

From: Victor W. Abramov <abr_at_ivcais.msk.ru>
Date: 1996/09/28
Message-ID: <AAYw9JoGA2_at_ivcais.msk.ru>#1/1


Roya Mehrfar wrote:
>
> I have a sqlplus statement with an order by that I need to retrieve only
> the first 25 rows. I tried where rownum < 26 but it trows away my order
> by because I would like to do the order by first and then get the first
> 25 rows.My statement looks like:
>
> select name, address
> from emp
> where city='LA'
> order by name;
>
> If I add rownum<26 it gets the first 25 and then orders by name, but I
> want to order by first.
>
> I thought of maybe adding 'minus' clause, but that didn't work either.
>
> Thanks for any help
>

Try such select:

select name, address
from emp e
where city='LA'
and 25 > (select count(*) from emp

            where city='LA'
            and e.name < name);


-----------------

Victor W. Abramov
abr_at_ivcais.msk.ru
Moscow, Russia Received on Sat Sep 28 1996 - 00:00:00 CEST

Original text of this message