AS clause is used to create a column alias to display in
result. Column alias is an alternative name that you specify to control how
column headings are displayed in a result. Generally column aliases are used if
column names are too long, too short, hard to type or cryptic.
To create column aliases :
Syntax of creating column aliases in select query :
SELECT column1 [AS] alias1,
column2 [AS] alias2,
…..
columnN [AS] aliasN
FROM table
Column alias immediately follows a column name in the SELECT
clause of a SELECT statement.
For example :
SELECT contactname AS CustomerName
FROM Customers
Enclose the alias in single or double quotes if it’s a
reserved keyword or if it contains a spaces, puntualtion or special characters.
For example :
SELECT contactname AS ‘User Name’ , customerid AS “User ID”,
city AS City
FROM Customers
Note that Column aliase doesn’t change the name of a column
in a table. As is also used to name derived columns i.e. whose values are
determined by expressions
For example :
SELECT ProductName, UnitsInStock
* UnitPrice AS TotalAmount
FROM products
Example of creating column aliases in select query :
SELECT ContactName AS 'Customer Name',
PostalCode AS "Post Code",
country AS Country
FROM Customers
Output
Customer
Name Post Code Country
Maria Anders 12209 Germany
Ana Trujillo
05021 Mexico
Antonio Moreno
05023 Mexico
Thomas Hardy WA1 1DP UK
Christina Berglund
S-958 22 Sweden
As in above example you can note that all column names are
changed by giving alias using AS clause.