Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

AS

AS

The AS command is utilized to assign an alias to a column or table, providing a temporary identifier for use within the query.

Alias for Columns

The given SQL statement establishes two aliases, assigning one to the CustomerID column and another to the CustomerName column.

Example

SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers; 

The provided SQL statement creates two aliases, highlighting that if the alias includes spaces, double quotation marks or square brackets are necessary.

Example

SELECT CustomerName AS Customer, ContactName AS [Contact Person] FROM Customers; 

The given SQL statement establishes an alias named “Address” by combining four columns: Address, PostalCode, City, and Country.

Example

SELECT CustomerName, Address + ‘, ‘ + PostalCode + ‘ ‘ + City + ‘, ‘ + Country AS Address
FROM Customers;

Note: For the SQL statement above to function in MySQL, utilize the following adjustment:

SELECT CustomerName, CONCAT(Address,‘, ‘,PostalCode,‘, ‘,City,‘, ‘,Country) AS Address
FROM Customers; 

Alias for Tables

The following SQL statement retrieves all orders from the customer with CustomerID=4 (Around the Horn). It employs the “Customers” and “Orders” tables, assigning them the aliases “c” and “o” respectively to streamline the SQL query.

Example

SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM Customers AS c, Orders AS o
WHERE c.CustomerName=“Around the Horn” AND c.CustomerID=o.CustomerID;