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 wherever a single value is expected, like in SELECT, WHERE, or SET clauses.
Click to reveal answer
beginner
How does a scalar subquery differ from other subqueries?
A scalar subquery returns a single value, while other subqueries can return multiple rows or columns. Scalar subqueries are used as single values in expressions.
Click to reveal answer
beginner
Example: What does this scalar subquery return?<br>
SELECT (SELECT COUNT(*) FROM employees) AS total_employees;
It returns the total number of employees as a single value in the column 'total_employees'.
Click to reveal answer
intermediate
Can a scalar subquery return more than one row or column?
No. If a scalar subquery returns more than one row or column, it causes an error because it expects exactly one value.
Click to reveal answer
intermediate
Where can scalar subqueries be used in SQL statements?
Scalar subqueries can be used in SELECT lists, WHERE clauses, HAVING clauses, and SET clauses where a single value is expected.
Click to reveal answer
What does a scalar subquery return?
✗ Incorrect
A scalar subquery returns exactly one value, which means one row and one column.
Where can you use a scalar subquery in SQL?
✗ Incorrect
Scalar subqueries are used where a single value is expected, such as in SELECT or WHERE clauses.
What happens if a scalar subquery returns more than one row?
✗ Incorrect
If a scalar subquery returns more than one row, SQL throws an error because it expects exactly one value.
Which of these is a valid scalar subquery?
✗ Incorrect
Option A returns a single value (maximum salary), which is valid for a scalar subquery.
Why use scalar subqueries?
✗ Incorrect
Scalar subqueries help get a single value from another query to use in expressions or conditions.
Explain what a scalar subquery is and give an example of where you might use it.
Think about a query inside parentheses that returns one number or text.
You got /3 concepts.
What error occurs if a scalar subquery returns more than one row? How can you avoid this?
Consider how to limit results to one row.
You got /3 concepts.