Lessons › SQL › Chapter 1: Reading data
SQL lesson
SELECT specific columns
Selecting specific columns means naming only the fields you want back instead of pulling everything stored in a table.
Try this lesson free →Example
Picking the columns you actually 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
- Start with one column. SELECT then the column name, then FROM and the table.
SELECT product_id FROM products; - Add a second column - separate them with a comma. Two columns come back.
SELECT product_id, price FROM products; - Swap the order of your columns and the result columns swap too. SQL respects the order you list.
SELECT price, product_id 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 →