What the TOP n Operator Does - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-05
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
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.