Table of ContentsPreviousNext

Database Migration


Restricting Number of Rows in Result Set

This subsection describes ways for restricting result sets in various databases and their conversion by SQLWays.

TABLE 24. Restricting Number of Rows in Result Set
Database
Clause
Descriptions
Microsoft SQL Server

TOP n [ PERCENT ]

The TOP clause of the SELECT statement limits the number of rows returned in the result set.
If PERCENT is not specified, n is the number of rows to return.
If PERCENT is specified, n is the percentage of the result set rows to return. In this case n must be an integer between 0 and 100.
If a SELECT statement that includes TOP also has an ORDER BY clause, the rows to be returned are selected from the ordered result set.
Example: The following example retrieves only first 7 rows from the query:
SELECT TOP 7 col1 FROM tab1
Oracle

ROWNUM

The ROWNUM pseudo column returns a number starting from 1 which indicates the order in which the row was selected in the result set.
 
ROWNUM can be used to limit the number of rows in the result set.
 
If a SELECT statement contains an ORDER BY clause, ROWNUM is assigned before the sort is done.
 
Example: The following example retrieves only first 7 rows from the query:
SELECT col1 FROM tab1 WHERE ROWNUM<=7;


Ispirer Systems
http://www.ispirer.com
ispirer@ispirer.com
Table of ContentsPreviousNext