SQL Keyword AS

The AS is used to define an alias name to a table or a column in an SQL statement.

  • If the alias name contains spaces, then it must be enclosed with double quotation marks or square brackets.
  • The alias name exists only for the duration of the query.

The below SQL uses alias names for the column names.

Run this on IDE

SELECT customer_id AS id, customer_name AS name
FROM customers;

 

The below SQL uses alias names for the column names, where the alias names contain spaces that are enclosed with double quotes or square brackets.

SELECT customer_name AS "Customer Name", contact_name AS [Contact Person]
FROM customers;

 

The below SQL uses alias names for the table names.

SELECT ord.order_id, ord.order_date, cust.customer_name
FROM customers AS cust, orders AS ord
WHERE cust.customer_name ="James Bond" 
AND cust.customer_id = ord.customer_id;

Related Links