SQL aliases and calculated columns
AS gives a column or table a short, readable name. You can also calculate new columns in SELECT, such as price times quantity. An alias from SELECT can't be used in WHERE, because WHERE runs first.
How do you calculate a column?
SELECT order_id, price * quantity AS revenue, ROUND(price * quantity * 0.2, 2) AS vatFROM order_lines;
How do table aliases help?
SELECT c.name, o.amountFROM customers AS cJOIN orders AS o ON o.customer_id = c.id;
Short aliases keep joins readable and make it clear which table each column comes from.
Why can't I use my alias in WHERE?
The database runs FROM and WHERE before SELECT, so revenue doesn't exist yet. Repeat the expression, WHERE price * quantity > 100, or wrap the query in a subquery or CTE. ORDER BY runs last, so ORDER BY revenue works everywhere.
Common mistakes
Dividing two whole numbers can return a whole number in some databases (5 / 2 = 2), so multiply by 1.0 first. Aliases with spaces need quotes, as in AS "order total", so prefer underscores.
Practise aliases and arithmetic
Updated November 2026.