Lessons › SQL › Chapter 1: Reading data
SQL lesson
SELECT specific columns
Instead of *, write the names of the columns you want. Only those come back, and every row stays. Put a comma between the names. They come back in the order you write them.
Try this lesson free →Example
Pick the columns you need
SELECT product_id, price
FROM products| product_id | price |
|---|---|
| P2001 | 299.99 |
| P2002 | 49.95 |
| P2003 | 22.5 |
| P2004 | 134.0 |
| P2005 | 89.75 |
Step by step
- List the columns you want after SELECT. Only those come back.
SELECT product_id, price FROM products - A comma goes between column names. No comma after the last one.
SELECT product_id, price FROM products - Columns come back in the order you list them.
SELECT product_id, price FROM products
Practice
1. Using the orders table, write a query to show only the order_date and category columns.
SELECT order_date, category FROM orders2. Using the products table, write a query to show only the brand and category columns.
SELECT brand, category FROM products3. Using the customers table, write a query to show only the signup_date and email columns.
SELECT signup_date, email FROM customers4. Using the inventory table, write a query to show only the stock_count and warehouse columns.
SELECT stock_count, warehouse FROM inventory5. Using the returns table, write a query to show only the return_id and refund_amount columns.
SELECT return_id, refund_amount 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 →