Re: 40 values in desc order

From: Richard H. E. Eiger <rheiger_at_renext.eiger.olivetti.ch>
Date: Fri, 8 Jan 1993 20:02:38 GMT
Message-ID: <1993Jan8.200238.534_at_osnbe.Olivetti.ch>


In article <6622.2b485a61_at_hayes.com> fgreene_at_hayes.com writes:
> In article <Bzo2t0.67_at_lut.fi>, hietanen_at_lut.fi (Pentti Hietanen) writes:
> >
> > What kind of sql sentence should we use to get 40 values
> > from database in descending order?
> >
> > Pentti Hietanen, student of Lappeenranta University of Technology, Finland.
> > internet: hietanen%lut.fi
>
>
> Probably the easiest way is to use the ROWNUM function. For example,
>
> SELECT field1, field2, fieldn
> FROM the_table
> WHERE ROWNUM < 40;
>

This will only limit the output to the first 40 rows. It will not order them in a predictible manner. If you want to order the rows descending you should probably use the "ORDER BY attr1, attr2... DESCENDING" clause. However this will not restrict the select to 40 rows. To do both you could

select <attribute1>,....
from tablename
where key_attr_list in (
select key_attr_list
from tablename
order by order_attr_list descending)
where rownum < 40;

This is probably rather SLOW. I am sure some SQL cracks will have a better solution.

--
                         
    ___           _____2
   /   )  /  /   /        Richard H. E. Eiger
  /_ _/  /__/   /__       Ing. Informatik HTL
 /\     /  /   /          Unregistered NeXT fan
/  \   /  /   /_____      rheiger_at_renext.eiger.olivetti.ch (NeXT mail welcome)
Received on Fri Jan 08 1993 - 21:02:38 CET

Original text of this message