Scalar subquery ( SELECT ... )
scalar subquery used as a value
What changes
- Input
- the inner query's sources, plus outer columns when correlated
- Output or change
- one value per outer row (NULL when no row; error 512 when more than one row)
Syntax at a glance
( SELECT single_column_expression FROM ... )
Work example
One value from a related query is needed in a SELECT list or predicate.
Run the sample and then make the inner query return zero rows and two rows. Keep the scalar result limited to one value.
Check your work Scalar subquery ( SELECT ... ). The subquery returns one value, NULL for no rows, and an error if it returns multiple rows.
Open Microsoft Learn for full syntax, permissions, and details for your version.