Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Finding the 10 smallest values in a column
On 12 Nov 1997 23:37:05 GMT, JF_Brown_at_pnl.gov (Jeff Brown) wrote:
>How about (I didn't test this, but I've used similar):
>
>Select VAL
> From TABLE
> Where ROWNUM < 11
> Order by VAL Asc
>;
>
>If you want values only once, make that "Select Distinct VAL".
>
Oh No, not again!
Querying by ROWNUM with an order by D*O*E*S N*O*T W*O*R*K!!!
It will select the first 10 rows it finds, and then sort them. To select the 10 smallest values, put the query in a cursor and only fetch the first 10 rows. This is the only way to do it that's guaranteed to work!
http://www.tswi.com
http://www.indusgroup.com
Replace domain name with the domain from the first URL before replying via email! Received on Thu Nov 13 1997 - 00:00:00 CST
![]() |
![]() |