CodeBlanks Logo Icon CodeBlanks

Column aliases with AS

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

query.sql
-- alias the column
SELECT price
FROM products

Sample solution

query.sql
SELECT price AS fiyat
FROM products

Expected 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

Question
SELECT name AS____
FROM customers;
Answer
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

All lessons in Beginner