Want to level up your SQL skills? Our SQL Fundamentals Course covers everything from basics to advanced queries.
🔥 Join the Udemy Course today and start learning!
📌 Click here to enroll now!
You work for an e-commerce platform that organizes products into different categories. Your task is to fetch all products that belong to a specific category, including the category details.
Write an SQL query to return all products under a specific category from the category and products tables.
- Select the following columns:
category_id(Category ID)category_name(Category Name)product_id(Product ID)product_name(Product Name)price(Product Price)
- The query must return only products that belong to a given category (select category by name not by id).
- Order the results by
product_namein ascending order.
Here’s an example of the category and products tables (The actual data can be found in init.sql):
| id | name | is_active |
|---|---|---|
| 1 | Electronics | true |
| 2 | Clothing | true |
| 3 | Books | false |
| id | category_id | name | price | is_active |
|---|---|---|---|---|
| 1 | 1 | Laptop | 999.99 | true |
| 2 | 1 | Smartphone | 699.99 | true |
| 3 | 2 | T-Shirt | 19.99 | true |
| 4 | 3 | Novel | 12.99 | false |
You can view the database ERD here:
Write a query to return only the products for a given category.
- 📌 Read the Setup Instructions to get everything up and running.
- 📝 Run your query.
- 💡 Need help? Check out the
solutions.sqlfile.
Watch the first Challenge if you need more help getting the code started.
🔗 Link to first Challenge 001
You only need to set up the database once for all challenges in Scenario A. Each scenario uses slightly different data, tailored to match the specific challenge requirements.