Limiting the number of rows returned from a query
You can create a report that contains a limited number of ordered entries.
- Construct an SQL query that selects and orders data as appropriate to your objective.
- Run the query and specify the row limit value that gives
the result you want.
The key elements are the ORDER BY clause of the SQL statement and the ROWLIMIT parameter of the RUN QUERY command.
For example, to create a report that contains the five managers with the most years of service, you could use the following query and QMF command.
SELECT NAME, YEARS FROM Q.STAFF WHERE JOB='MGR' ORDER BY YEARS DESC
RUN QUERY (ROWLIMIT=5
NAME YEARS --------- ------ JONES 12 QUILL 10 HANES 10 LU 10 LEA 9