What the TOP n Operator Does - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.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.