Aliases are used to improve readability. Aliasing can be applied to tables or views in the FROM clause or to columns in the SELECT clause.
I. Aliasing Tables
  • By assigning an alias to a table, we can use the alias in the entire query instead of using the table name.
  • Using alias is required when self-join command is used.
  • An optional “AS” keyword can be used to create an alias.
SYNTAX I (Top number of rows):
SELECT T.Column1, T.Column2
FROM Table1 AS T
SYNTAX II (Without “AS” keyword):
SELECT T.Column1, T. Column2
FROM Table1 T
II. Aliasing Columns
  • Aliasing of columns are done only in the SELECT clause.
  • SQL SERVER does not allow referencing column by its alias in the WHERE, GROUP BY or HAVING clauses. However you can use refer to a column by its alias in the ORDER BY clause.
  • Just like aliasing table name, an optional “AS” keyword can be used to create an alias.
SYNTAX:
SELECT T.Column1 AS ‘Column 1’, T.Column1 + T.Column2 AS ‘Column 1 and 2’
FROM Table1 AS T