Recall & Review
beginner
What is a scalar subquery in SQL?
A scalar subquery is a subquery that returns exactly one value (one row and one column). It can be used in places where a single value is expected, such as in the SELECT list.
Click to reveal answer
beginner
Can a scalar subquery return multiple rows or columns?
No, a scalar subquery must return exactly one row and one column. Returning more than one row or column causes an error.
Click to reveal answer
intermediate
How is a scalar subquery used in a SELECT statement?
It is placed inside the SELECT clause to compute a value for each row, for example: SELECT name, (SELECT MAX(score) FROM scores WHERE scores.user_id = users.id) AS max_score FROM users;
Click to reveal answer
intermediate
What happens if a scalar subquery returns no rows?
If a scalar subquery returns no rows, it returns NULL in the SELECT statement.
Click to reveal answer
intermediate
Why use a scalar subquery instead of a JOIN?
Scalar subqueries can be simpler to write and understand when you need a single value related to each row, especially for aggregation or lookup. JOINs are better for multiple related rows.
Click to reveal answer
What does a scalar subquery return?
✗ Incorrect
A scalar subquery returns exactly one value, meaning one row and one column.
Where can you use a scalar subquery in SQL?
✗ Incorrect
Scalar subqueries are often used in the SELECT clause to compute a single value per row.
What happens if a scalar subquery returns no rows?
✗ Incorrect
If no rows are returned, the scalar subquery returns NULL.
What error occurs if a scalar subquery returns more than one row?
✗ Incorrect
Scalar subqueries must return one row; more than one row causes an error.
Which is a good use case for scalar subqueries?
✗ Incorrect
Scalar subqueries are useful for getting one value per row, like an aggregate.
Explain what a scalar subquery is and how it is used in a SELECT statement.
Think about a small query inside the SELECT that gives one value per row.
You got /4 concepts.
What errors or results can happen if a scalar subquery returns zero or multiple rows?
Consider what SQL expects from a scalar subquery's output.
You got /3 concepts.