You can place a ScalarSubquery anywhere an Expression is permitted. A ScalarSubquery turns a SelectExpression result into a scalar value because it returns only a single row and column value.
The query must evaluate to a single row with a single column.
-- avg always returns a single value, so the subquery is -- a ScalarSubquery SELECT NAME COMM FROM STAFF (SELECT AVG(BONUS + 800) FROM EMPLOYEE WHERE COMM < 5000); -- Introduce a way of "generating" new data values, -- using a query which selects from a VALUES clause (which is an alternate form of a fullselect). -- This query shows how a table can be derived called "X" having 2 columns "R1" and "R2" and 1 row of data. SELECT R1,R2 FROM (VALUES('GROUP 1','GROUP 2')) AS X(R1,R2);
Table of Contents