Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 1.44 KB

Aliases.md

File metadata and controls

65 lines (52 loc) · 1.44 KB

Aliases are "alternate names" used for Columns and Tables.

SELECT column_name as column_alias
FROM table_name

or

SELECT column_name  column_alias /**** without as ****/
FROM table_name

Some examples using column aliases

Example1

SELECT firstname,lastname,age,birthdate as DateofBirth
FROM maincontact

Example2

SELECT firstname,lastname,age,birthdate  DateofBirth /**** without as ****/
FROM maincontact

Example3

SELECT firstname,lastname,age,birthdate as  'Date of Birth' 
FROM maincontact

Example4

SELECT firstname,lastname,age,birthdate "Date of Birth"
FROM maincontact

The readability of a SELECT statement can be improved by giving a table an alias, also known as a correlation name or range variable. A table alias can be assigned either with or without the AS keyword:

table_name AS table alias

or

table_name table_alias
SELECT table_alias.column_name, table_alias.column_name
FROM table_name table_alias
SELECT table_alias.column_name as column_alias
FROM table_name table_alias

In the following example the alias c is assigned to Customer and the alias s is assigned to Store.

SELECT c.CustomerID, s.Name
FROM Sales.Customer AS c
JOIN Sales.Store AS s
ON c.CustomerID = s.BusinessEntityID ;