Re: 40 values in desc order

From: Michael Friedman <mfriedma_at_uucp>
Date: Tue, 5 Jan 1993 20:07:12 GMT
Message-ID: <1993Jan5.200712.12169_at_oracle.us.oracle.com>


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;

First off, you need to do an order by.

Secondly, unless you are satisfied with any 40 this will not work because rownum is assigned before the order_by.

If you want the top 40 then try

Select fields
From the_table t1
Where 40 >= (select count(*) from the_table t2 where

                        t2.order_field > t1.order_field)
Order by order_field DESC

Good Luck         

-- 
-------------------------------------------------------------------------------
I am not an official Oracle spokesman.  I speak for myself and no one else.
Received on Tue Jan 05 1993 - 21:07:12 CET

Original text of this message