Why rename columns?
When you query a database, column names are often technical — cust_id, ord_amt, cat_nm. Aliases let you present results with clean, readable labels — without changing the actual database.
They matter especially when:
- Sharing reports with non-technical people
- Combining columns with expressions
- Avoiding ambiguous column names in JOINs
Basic alias with AS
sql
SELECT first_name AS name
FROM customers;
The result shows name as the column header — not first_name.
Multi-word aliases
If your alias has a space, wrap it in double quotes.
sql
SELECT
first_name AS "First Name",
last_name AS "Last Name",
city AS "Customer City"
FROM customers;
Note: Single-word aliases don't need quotes. Multi-word aliases do. Both styles work — consistency matters more than which you pick.
Aliases on expressions
This is where aliases become essential. Without one, the column header is the raw expression.
sql
-- Without alias — ugly column header
SELECT price * quantity FROM order_items;
-- With alias — clean and clear
SELECT price * quantity AS line_total
FROM order_items;
AS is optional
The AS keyword is technically optional — you can just put the alias after the column name. But using AS makes queries much easier to read.
sql
-- Both work the same
SELECT first_name name FROM customers;
SELECT first_name AS name FROM customers;
Always use AS. It signals intent clearly.
Practice
From the customers table, select first_name and last_name. Alias them as "First Name" and "Last Name".
Hint: Use double quotes for aliases with spaces
Solution
SELECT first_name AS "First Name", last_name AS "Last Name" FROM customers
From the products table, select product_name and price. Rename price as "selling_price". Also add a third column that calculates price * 1.18 labeled as "price_with_gst".
Hint: You can do arithmetic inside SELECT alongside column names
Solution
SELECT product_name, price AS selling_price, price * 1.18 AS price_with_gst FROM products