Decode Analytics

View Original

Aliases

SQL Aliases are a temporary name given to a table, view, or a column in a table for the specific query.  Aliases make columns easier to identify and allow for shorthand text.  Aliases are used to make complex SQL syntax easier to read where there are many joins and/or aggregations. The keyword “as” is used to denote an alias.

SQL Alias Column Syntax:

SELECT Column1 as NewName

FROM Table_Name

Alias Table Syntax:

SELECT

NewName .Column1,

NewName .Column2,

NewName .Column3

FROM Table_Name as NewName

Alias In Join Syntax:

SELECT

T1 .Column1,

T1.Column2,

T2.Column1,

T2.Column2

FROM Table1 as T1, Table2 as T2

WHERE T1.Column1=T2.Column1

Example:

Lets rename the column names of the following table

See this content in the original post


Results:

See this content in the original post

Table Alias Example:

See this content in the original post



JOIN Alias Example:

See this content in the original post

SQL Tutorial

See this content in the original post