TOP Function Syntax | Teradata Vantage - 17.10 - TOP - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - Time Series Tables and Operations

Advanced SQL Engine
Teradata Database
Release Number
Release Date
July 2021
Content Type
Programming Reference
Publication ID
English (United States)

Returns the largest number_of_values in the value_expression for each group, with or without ties. TOP is a single-threaded function.

To invoke the time series version of this function, use the GROUP BY TIME clause. For more information, see GROUP BY TIME Clause.


TOP [ WITH TIES ] ('number_of_values', 'value_expression')

Syntax Elements

Teradata integer value representing the number of values to return.
A literal or column expression from which the top values are taken.

The value_expression cannot be a reference to a view column derived from a function, and cannot contain any ordered analytical or aggregate functions.

Return Value

The return value is the same as the input data type.

Nulls are not included in the computation.

Usage Notes

TOP is valid only for numeric data.

WITH TIES implies the rows returned by the query include the specified number of rows in the ordered set for each time bucket, plus any additional rows where the sort key value is the same as the value of the sort key in the last row satisfying the specified number or percentage of rows. If this clause is omitted and ties are found, the earliest value in terms of timecode is returned.