Difficulty: Beginner
Estimated time: 5–10 minutes
SQL concepts: SELECT, choosing columns, result sets
Goal: Retrieve only the columns you need (a core real-world SQL habit).
The Scenario
You’re working with an e-commerce database. A product manager asks for a simple list of products showing:
- Product name
- Price
- Category
They do not want internal columns like IDs, created timestamps, or inventory details.
Your task is to write a query that returns only the requested columns.
Database Table
products
| column_name | type | description |
|---|---|---|
| product_id | INTEGER | Unique product ID |
| name | TEXT | Product name |
| category | TEXT | Product category |
| price | DECIMAL | Product price |
| stock_qty | INTEGER | Units in stock |
| created_at | TIMESTAMP | When the product was created |
Sample Data (for context)
| product_id | name | category | price | stock_qty | created_at |
|---|---|---|---|---|---|
| 101 | Wireless Mouse | Accessories | 24.99 | 120 | 2025-01-10 09:00:00 |
| 102 | Mechanical Keyboard | Accessories | 89.00 | 45 | 2025-01-12 10:30:00 |
| 103 | 27-inch Monitor | Displays | 229.99 | 18 | 2025-01-15 12:20:00 |
| 104 | USB-C Hub | Accessories | 34.50 | 70 | 2025-01-18 14:00:00 |
| 105 | Laptop Stand | Workspace | 39.99 | 32 | 2025-01-21 16:10:00 |
Your Task
Write a SQL query that returns:
namepricecategory
From the products table.
Expected Output
Your result should look like this:
| name | price | category |
|---|---|---|
| Wireless Mouse | 24.99 | Accessories |
| Mechanical Keyboard | 89.00 | Accessories |
| 27-inch Monitor | 229.99 | Displays |
| USB-C Hub | 34.50 | Accessories |
| Laptop Stand | 39.99 | Workspace |
Constraints
- Do not use
SELECT * - Return only the three requested columns
- The column order should be:
name,price,category
Hint (Optional)
In SQL, you specify the columns you want right after SELECT, separated by commas.
SELECT
name,
price,
category
FROM products;
Explanation
SELECT name, price, categorytells the database exactly which columns to return.FROM productstells it which table to read from.- This avoids pulling unnecessary data, which is more efficient and is best practice in production SQL.
Common Mistakes
- Using
SELECT *- Works, but returns extra columns you didn’t ask for (and often slows real systems).
- Wrong column order
- Many automated checkers and dashboards expect a specific ordering.
- Misspelling column names
- SQL will error if
categoryis typed incorrectly.
- SQL will error if
Optional Extension (Mini Bonus)
Modify your query to return only products where the category is Accessories.
(You’ll learn WHERE in Challenge #2, but it’s fine to try.)
🔗 View reference solution on GitHub
(After you’ve tried the challenge)