SQL Alias

The SQL Alias is the name given to a table or column of a database. Usually SQL Alias is used when writing a complex SQL query containing different columns and/or tables by giving the different columns and/or tables different names known as aliases.

SQL statement containing Alias for Columns

SELECT column_name
AS alias_name
FROM table_name

SQL statement containing Alias for Tables

SELECT column_name(s)
FROM table_name
AS alias_name

SQL Alias Example

If we have a table called “Members” and another table called “Orders”, then we can give the table “Members” an alias “m” and “Orders” an alias “o”. The alias name can be any name that is preferred since it is just a way to refer to the table with another simple name.

SQL statement without the use of Alias

SELECT Orders.Id, Members.FirstName, Members.LastName
FROM Members ,
Orders
WHERE Members.FirstName=’Elvis’ AND Members.LastName=’Daniels’

SQL statement with the use of Alias

SELECT o.Id, m.FirstName, m.LastName
FROM Members AS m,
Orders AS o
WHERE m.FirstName=’Elvis’ AND m.LastName=’Daniels’