SQL AS (aliases)
Give a column or a table a new name for this query.
Syntax
SELECT expression AS new_name FROM table AS t;
Column aliases make results readable; table aliases make joins shorter. AS is optional for tables in most databases, but writing it is clearer.
Example
Query (on the shop database used in the SQL course)
SELECT p.name AS product, p.price * 2 AS price_for_two FROM products AS p LIMIT 4;
Result
| product | price_for_two |
|---|---|
| Wireless mouse | 58.0 |
| Mechanical keyboard | 238.0 |
| USB-C hub | 98.0 |
| 27-inch monitor | 658.0 |
4 rows
Good to know. An alias from SELECT cannot be used in WHERE (WHERE runs first), but can be used in ORDER BY.
Related
Learn it step by step in the free lesson SELECT: Choosing Columns, with exercises that check your queries.