17.10 - ORDER BY Clause Usage - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Detailed Topics

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
imq1591724555718.ditamap
dita:ditavalPath
imq1591724555718.ditaval
dita:id
jbg1472252759029

You can specify an ORDER BY clause in a view definition only if you also specify either the TOP n or TOP m PERCENT option. Without a TOP n clause, the results on which the ORDER BY should be applied is ambiguous, and therefore not meaningful semantically.

An ORDER BY clause is semantically meaningful when used with a TOP n subselect operation because it affects the actual results of the subselect in the view definition. For TOP n subselect operations, the ORDER BY specification also controls the final result of the subselect operation.

If you want to create a view that also includes the WITH TIES option for TOP n, then you must also specify an ORDER BY clause; otherwise, the system ignores the WITH TIES specification.