Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB2 Equivalent of 'TOP' or 'FIRST' 1

Status
Not open for further replies.

stoggers

Vendor
May 30, 2001
93
0
0
US
Hi,

Is there an equivalent in DB2 to the TOP or FIRST directive in other varieties of SQL - ie to return only the first n rows of a query.

If not, is there a query which will simulate TOP or FIRST.

Thanks,

Mike Stogden.
 
The obvious answer is to use "order by" to put the rows satisfying your select in the desired sequence, and close your cursor after nnn fetches.
The last issue of DB2 magazine indicates that with version 7, you can put in a "fetch first 1 row" on a query if only one row is required. I'm not sure what "fetch first 5 row" might yield.
See article:
 
If you want the first 5 rows, you should use the clause:

FETCH FIRST 5 ROWS

It will act just like the SQL Server TOP clause.

Regards,
Suresh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top