Recall & Review
beginner
What is a subquery in SQL?
A subquery is a query nested inside another query. It helps to get intermediate results that the main query can use.
Click to reveal answer
beginner
Why do we use subqueries instead of writing one big query?
Subqueries break complex problems into smaller parts, making queries easier to write and understand.
Click to reveal answer
intermediate
How do subqueries help in filtering data?
Subqueries can find specific values first, then the main query uses those values to filter results precisely.
Click to reveal answer
intermediate
Can subqueries be used in SELECT, WHERE, and FROM clauses?
Yes, subqueries can appear in SELECT to calculate values, in WHERE to filter rows, and in FROM to act like temporary tables.
Click to reveal answer
beginner
Give a real-life example where subqueries are useful.
Imagine finding employees who earn more than the average salary. A subquery calculates the average salary, then the main query finds employees above it.
Click to reveal answer
What is the main reason to use a subquery in SQL?
✗ Incorrect
Subqueries help by breaking complex queries into smaller, manageable parts.
Where can a subquery NOT be used?
✗ Incorrect
Subqueries are used inside queries, not in schema definitions.
Which of these is a benefit of using subqueries?
✗ Incorrect
Subqueries allow filtering based on values calculated inside the subquery.
A subquery that returns multiple rows can be used with which operator?
✗ Incorrect
The IN operator works with subqueries returning multiple rows.
What does a subquery inside the FROM clause act like?
✗ Incorrect
Subqueries in FROM act like temporary tables for the main query.
Explain why subqueries are useful when writing SQL queries.
Think about how subqueries help manage complexity and filtering.
You got /4 concepts.
Describe a scenario where using a subquery is better than a single flat query.
Consider filtering based on a calculated value like average salary.
You got /4 concepts.