SQL Tutorial · SQL Basics · Lesson 11 of 36
SQL Aliases
Rename columns and tables with AS for readable queries.
Column aliases
AS gives a column a new name in the result — essential for calculated columns:
SELECT name AS product, price AS unit_price, ROUND(price * 1.2, 2) AS price_with_vat
FROM products ORDER BY price DESC LIMIT 4;
Output
product | unit_price | price_with_vat 4K Monitor | 329 | 394.8 Robot Kit | 120 | 144 Mechanical Keyboard | 89 | 106.8 Standing Desk Mat | 59.9 | 71.88
Table aliases
Short table aliases keep queries with several tables readable (you'll use them constantly with joins):
SELECT p.name, p.price
FROM products AS p
WHERE p.category_id = 3;
Output
name | price Coffee Mug | 12 Desk Lamp | 45 Standing Desk Mat | 59.9
Quote aliases containing spaces with double quotes: AS "Unit Price".
Test yourself
Which keyword creates an alias?
ASALIASNAMERENAME
Show answer
Answer: AS