Recall & Review
beginner
What is a subquery in the WHERE clause?
A subquery in the WHERE clause is a query inside another query that helps filter results based on values returned by the inner query.
Click to reveal answer
beginner
How does a subquery in the WHERE clause work?
The outer query uses the result of the subquery to decide which rows to include. The subquery runs first and returns values that the outer query compares against.
Click to reveal answer
beginner
Example: SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments WHERE location = 'New York');<br>What does this query do?
It finds all employees who work in departments located in New York. The subquery finds department IDs in New York, and the outer query selects employees in those departments.
Click to reveal answer
intermediate
Can a subquery in the WHERE clause return multiple values?
Yes, subqueries can return multiple values when used with operators like IN, ANY, or ALL to compare against multiple results.
Click to reveal answer
intermediate
What is the difference between using '=' and 'IN' with a subquery in the WHERE clause?
'=' expects the subquery to return a single value, while 'IN' allows the subquery to return multiple values to match any of them.
Click to reveal answer
What does a subquery in the WHERE clause do?
✗ Incorrect
A subquery in the WHERE clause filters rows by using values returned from the inner query.
Which operator allows a subquery to return multiple values in the WHERE clause?
✗ Incorrect
The IN operator allows the subquery to return multiple values to match any of them.
What happens if a subquery in the WHERE clause returns no rows?
✗ Incorrect
If the subquery returns no rows, the outer query finds no matching rows and returns no results.
Which of these is a valid use of a subquery in the WHERE clause?
✗ Incorrect
Option D correctly uses a subquery to compare price to the average price.
Can a subquery in the WHERE clause reference columns from the outer query?
✗ Incorrect
A correlated subquery references columns from the outer query and runs once per outer row.
Explain how a subquery in the WHERE clause helps filter data with an example.
Think about how the inner query returns values that the outer query uses to decide which rows to keep.
You got /3 concepts.
Describe the difference between using '=' and 'IN' with subqueries in the WHERE clause.
Consider what happens if the subquery returns one value or many values.
You got /3 concepts.