What the TOP n Operator Does - 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™
You can use the TOP n operator in these ways:
  • The TOP n operator returns only a subset of the rows in the query result set. For example, this query returns 10 rows from the orders table:
         SELECT TOP 10 *
         FROM orders;
  • To obtain a subset of the data from an ordered set, specify the TOP n operator with an ORDER BY clause. For example, this query returns the last five orders shipped:
         SELECT TOP 5 *
         FROM orders
         ORDER BY ship_date DESC;
  • If the TOP n operator specifies a number greater than the number of rows in the query result set, then the query returns all of the rows in the query result set without returning an error.
  • As the size of n increases, the performance of TOP n gradually degrades.
  • You can use parameters to pass values for n from:
    • CREATE MACRO, see Teradata Vantage™ - SQL Data Definition Language Syntax and Examples, B035-1144.
    • CREATE PROCEDURE (SQL Form), see Teradata Vantage™ - SQL Data Definition Language Detailed Topics , B035-1184 .
    • USING Request Modifier, see USING Request Modifier.