Example: Ordering on a Column Name Alias - 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™

Define a column named j in table t1.

The following statement returns an error because j is defined to be an alias for the expression SUM(t1.j). However, when it is used in the ORDER BY clause, the system resolves it to the column j and not the expression aliased by j:

     SELECT t1.i, SUM(t1.j) AS j, t1.k
     FROM t1
     GROUP BY 1,3
     ORDER BY j;

The following statement works because the column name alias jj is not the same as the column name j, and there is no column named jj in the table definition.

     SELECT t1.i, SUM(t1.j) AS jj, t1.k
     FROM t1
     GROUP BY 1,3
     ORDER BY jj;