|
|
Re: Limit records returned by a select - with order by [message #374727 is a reply to message #374701] |
Wed, 27 June 2001 02:51 |
Jeff Nichols
Messages: 1 Registered: June 2001
|
Junior Member |
|
|
that limits the rows returned BEFORE any order by clause is applied -- not what you might think or hope.
To limit the rows returned AFTER an order by clause you have to put the order by in a subquery and then applie the rownum condition to the sorted results of the subquery:
SELECT my_num FROM (SELECT my_num FROM my_table ORDER BY my_num DESC) WHERE rownum <= 1;
This will have one result row with the highest value for my_num. It's a lame example because you could do the same with max(my_num) but you get the picture... See the Link below for Oracle docs on ROWNUM (requires free registration).
|
|
|