Column aliases with AS
- SQL course
- Beginner
- Lesson 4/115
- 4 min
Learn to give columns short names with AS.
Column aliases with AS
To give a column a different name in the result, use the AS keyword. It changes the header; it does not touch the table.
SELECT name AS customer_name
FROM customers;The result header shows customer_name instead of name. Useful for reports and readable output. AS is optional; name customer_name also works.
name AS musteri_adi is selected from customers.
Column aliases with AS — details
You can alias a calculation or function result too. This is especially useful to name otherwise headerless columns.
SELECT price * 1.18 AS price_with_tax
FROM products;The result shows the tax-included price under the price_with_tax header. Without an alias the column header would be unclear. If the alias name contains a space, wrap it in quotes or brackets; for plain names this is not needed.
Practice Column aliases with AS
Select the price column from products with the alias unit_price.
Starter code
-- alias the column
SELECT price
FROM productsSample solution
SELECT price AS fiyat
FROM productsExpected output
fiyat 5 12
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does AS do?
- Renames the table
- Adds a new column
- Deletes rows
- Gives the column a different name in the result Correct answer
Explanation: AS gives a column an alias in the result.
2 Alias with AS
SELECT name AS____
FROM customers;
SELECT name AS musteri_adi
FROM customers;
Explanation: musteri_adi is the right answer.
3 Column aliases with AS: match the terms
| Term | Meaning |
|---|---|
AS |
gives alias |
name |
column |
customer_name |
new name |
FROM |
table |