ORDER BY Clause Usage - Analytics Database - Teradata Vantage

SQL Data Definition Language Detailed Topics

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2024-12-13
dita:mapPath
vuk1628111288877.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
jbg1472252759029
lifecycle
latest
Product Category
Teradata Vantage™

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.