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 →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 productsStep by step
- AS gives the column a new name in the result.
SELECT order_id, revenue AS total_revenue FROM orders - The table keeps its name. AS only changes what you see.
SELECT order_id, revenue AS total_revenue FROM orders - Use underscores instead of spaces, so it reads as one name.
SELECT order_id, revenue AS total_revenue FROM orders
Practice
1. Write a query on the orders table to show the revenue column renamed as total_revenue.
SELECT revenue AS total_revenue FROM orders2. Write a query on the products table to show the product_id column renamed as item_code.
SELECT product_id AS item_code FROM products3. Write a query on the customers table to show the phone column renamed as contact_number.
SELECT phone AS contact_number FROM customers4. Write a query on the inventory table to show the stock_count column renamed as units_available.
SELECT stock_count AS units_available FROM inventory5. 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 returnsLearn 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 →