Specifies that either an explicit number of rows or an explicit percentage of rows is to be returned from the query result set.
Syntax Elements
- TOP n
- The query returns a specified number of rows or a percentage of available rows.
- integer
- integer PERCENT
- A nonzero, positive INTEGER literal indicating the number of rows to return.
- decimal
- decimal PERCENT
- A nonzero, positive DECIMAL literal indicating the number of rows to return.
- PERCENT
- The integer or decimal value indicates a percentage of the rows to return.
- WITH TIES
- Rows returned by the query include the specified number or percentage of rows in the ordered set produced by the ORDER BY clause, plus any additional rows where the value of the sort key is the same as the value of the sort key in the last row that satisfies the specified number or percentage of rows.
ANSI Compliance
TOP n is a Teradata extension to the ANSI SQL:2011 standard.
Other SQL dialects use similar operators with names such as:
- FIRST n
- LIMIT n
- SET ROWCOUNT n
- STOP AFTER n