AS
operator
The AS
operator in SQL-queries can be used in several different functions.
Specifying names for columns in a query
The AS
operator can be used to specify names (aliases) for columns in a table that will be output as the result of a query or used in the query itself:
SELECT
name AS Student
FROM students
If the given name contains a space, it must be enclosed in inverted commas:
SELECT
name AS "Student Name"
FROM students
Specifying names for tables in a query
The AS
operator can be used to specify names (aliases) for tables that are used in a query:
SELECT o.OrderID, o.OrderDate, c.CustomerName
FROM
Customers AS c,
Orders AS o
WHERE
c.CustomerName="Tengri" AND c.CustomerID=o.CustomerID;
Here in the query, the aliases c
and o
for the tables Customers
and Orders
that are queried are used for brevity.
Specifying a query when creating a table
When creating a table, the AS
operator can be used to specify a data query, the result of which will be written to the table being created:
CREATE TABLE films_recent AS
SELECT * FROM films WHERE date_prod >= '2025-01-01';
In this case, you can also use FROM-first syntax and discard SELECT *
. Then the query (equivalent to the previous one) will look like this:
CREATE TABLE films_recent AS
FROM films WHERE date_prod >= '2025-01-01';