Use scalar subqueries
- Last Updated: February 11, 2026
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
A scalar subquery is a parenthesized query expression that returns a single value (one row of a single column).
Scalar subqueries can be of the following types:
- Correlated scalar subquery: Returns a single value for each row of the correlated outer table. A scalar subquery can be a correlated to table(s) in the containing query block where it returns a single value for each outer row.
- Uncorrelated scalar subquery: Returns a single value to the containing query.
A correlated scalar subquery is used in the same way that a column is used, while an uncorrelated scalar subquery is used in the way that a constant value is used.
Scalar subqueries are not valid in the following cases:
- When used in
ORDER BYandGROUP BYclauses - When subqueries include
UNION - When subqueries include LOB data types
A scalar subquery uses the following syntax:
Syntax
|
- scalar_subquery
Selects exactly one column or expression in its select list.
The data type of a scalar_subquery is same as that of the column of the query expression that it contains.
If the scalar_subquery returns more than one row, an error occurs stating that the subquery returns multiple rows. If the scalar_subquery returns 0 rows, then the scalar_subquery value is
NULL.
A scalar subquery expression is valid in most syntax that calls for an expression (expr). Scalar subqueries can be used in the following components of SQL statements:
SELECTstatement- Select list
WHEREclause:ONclause predicatesHAVINGclause
INSERTstatementVALUESclause
UPDATEstatementWHEREclause
DELETEstatementWHEREclause
The following examples illustrate the use of scalar subqueries
in components of the SELECT statement:
|
|
|
|
The following examples illustrate the use of scalar subqueries
in components of the INSERT statement:
|
The following examples illustrate the use of scalar subqueries
in components of the DELETE statement:
|
The following examples illustrate the use of scalar subqueries in triggers and views:
|
|
The following examples illustrate the use of scalar subqueries as expressions:
|
|
|
|