Home Home    Forum    Blog    Feed your aggregator (RSS 2.0)

The Johnnynine Weblog - Retrieve the top X row's in Oracle
A weblog by Johnny Hughes
 
 Tuesday, July 12, 2005

To retrieve an unordered set of rows:

SELECT * FROM orders WHERE rownum < 2 ;

To retrieve rows of an ordered result set:

SELECT o.* FROM (SELECT * FROM orders ORDER BY orderid) o
WHERE rownum < 2 ;

This is because rownum is assigned to the result set when the records are retrieved and before they are sorted.

Note: In Sql Server, use the TOP keyword.

Tuesday, July 12, 2005 4:42:51 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0]   Database | Oracle  | 
Copyright © 2009 Johnny Hughes. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.