- Categories:
TOP <n>¶
Constrains the maximum number of rows returned by a statement or subquery.
- See also:
Syntax¶
Parameters¶
nThe maximum number of rows to return in the result set.
Usage notes¶
An ORDER BY clause is not required; however, without an ORDER BY clause, the results are non-deterministic because results within a result set are not necessarily in any particular order. To control the results returned, use an ORDER BY clause.
When TOP <n> and ORDER BY are at different nesting levels in a query, results can be unpredictable. For details and examples, see the LIMIT / FETCH usage notes.
nmust be a non-negative integer constant.TOP
nand LIMITcountare equivalent.
Examples¶
The following example shows the effect of TOP N. For simplicity, these queries omit the ORDER BY clause and assume that the output order is always the same as shown by the first query. Real-world queries should include an ORDER BY clause.