select top 20 [message #10714] |
Wed, 11 February 2004 14:33 |
Erin
Messages: 17 Registered: October 2001
|
Junior Member |
|
|
How do you select top 20 records, based on value of a field?
so basically: select order_id, amount from orders
Want the top 20 orders based on highest amount.
Tried using order by amount desc and rownum < 21 but that didn't work.
Really only want the top 20 so i can automate a script for the output.
Thanks
|
|
|
Re: select top 20 [message #10716 is a reply to message #10714] |
Wed, 11 February 2004 15:07 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
The ORDER BY needs to be applied prior to the ROWNUM evaluation, so just move the ORDER BY into an inline view:
select *
from (select order_id, amount
from orders
order by amount desc)
where rownum <= 20;
|
|
|
|