TOP Clause Syntax | SQL SELECT Statements | Teradata Vantage - TOP Clause Syntax - Advanced SQL Engine - Teradata Database

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™
TOP { integer | decimal } [ PERCENT ] [ WITH TIES ]
You cannot specify NORMALIZE with TOP.

Syntax Elements

integer
A nonzero, positive INTEGER literal indicating the number of rows to return.
If the PERCENT option is specified, the system returns integer% of the total rows available, where 100 ≥ integer >  0.
decimal
A nonzero, positive DECIMAL literal indicating the number of rows to return.
If the PERCENT option is specified, the system return decimal% of the total rows available, where 100 ≥ decimal  >  0.
If the PERCENT option is not specified, decimal cannot include a decimal point.
PERCENT
The integer or decimal value indicates a percentage of the rows to return.
The number of rows returned is (n/100 * result set row count), where n is the integer or decimal value.
If the number is not an integer, and the fractional part of the number ≥ 0.000000000000001, the next highest integer is used.
For fractions < 0.000000000000001, the number is truncated.
The TOP n operator is referred to as TOP m when you specify the PERCENT option for clarification purposes.
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.
The WITH TIES option is ignored if the SELECT statement does not also specify an ORDER BY clause.