Filtering Products Using Subqueries in WHERE Clause
📖 Scenario: You work for an online store that sells various products. The store keeps track of products and their categories in a database. You want to find products that belong to categories with a specific condition.
🎯 Goal: Build a SQL query that uses a subquery inside the WHERE clause to filter products based on their category.
📋 What You'll Learn
Create a table called
categories with columns category_id (integer) and category_name (varchar).Create a table called
products with columns product_id (integer), product_name (varchar), and category_id (integer).Insert specific rows into both tables as given.
Write a SQL query that selects product names from
products where the category_id is in the set of category IDs returned by a subquery filtering categories by name.Use a subquery inside the
WHERE clause.💡 Why This Matters
🌍 Real World
Filtering products by category is a common task in e-commerce databases to show users relevant items.
💼 Career
Understanding subqueries in WHERE clauses is essential for database querying roles, data analysis, and backend development.
Progress0 / 4 steps