BBampaa

Lessons › SQL › Chapter 1: Reading data

SQL lesson

Column aliases with AS

A column alias gives a column a temporary, human-friendly name in your results without changing anything in the actual database.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Renaming Retail Columns with AS

SELECT product_id AS product_code,
       product_name AS item_name,
       category AS product_category,
       price AS selling_price
FROM products

Result:

Step by step

  1. Rename one column with AS. The original column name stays in the table; only the result label changes.
    SELECT product_id AS product_code
    FROM products;
  2. Alias a second column the same way - column name, then AS, then the new label.
    SELECT product_id AS product_code, product_name AS item_name
    FROM products;
  3. You can alias as many columns as you like. Each pair follows the same pattern.
    SELECT product_id AS product_code, product_name AS item_name, category AS product_category
    FROM products;

Practice

Try each one in your head first, then open the answer.

1. Write a query on the orders table to show the revenue column renamed as total_revenue.
SELECT revenue AS total_revenue FROM orders
2. Write a query on the products table to show the product_id column renamed as item_code.
SELECT product_id AS item_code FROM products
3. Write a query on the customers table to show the phone column renamed as contact_number.
SELECT phone AS contact_number FROM customers
4. Write a query on the inventory table to show the stock_count column renamed as units_available.
SELECT stock_count AS units_available FROM inventory
5. Write a query on the returns table to show the return_date column renamed as refund_date.
SELECT return_date AS refund_date FROM returns

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed