BBampaa

Lessons › SQL › Chapter 1: Reading data

SQL lesson

Column aliases with AS

AS gives a column a new name in your result, like total_revenue instead of revenue. Only the result changes. The table keeps its own names. Use underscores, not spaces.

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

Example

Give a column a new name

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. AS gives the column a new name in the result.
    SELECT order_id, revenue AS total_revenue FROM orders
  2. The table keeps its name. AS only changes what you see.
    SELECT order_id, revenue AS total_revenue FROM orders
  3. Use underscores instead of spaces, so it reads as one name.
    SELECT order_id, revenue AS total_revenue FROM orders

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 return_date renamed as refund_date, and refund_amount renamed as amount_back.
SELECT return_date AS refund_date, refund_amount AS amount_back 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