ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Read Accesses → SELECT → SELECT - WHERE → WHERE - sql_cond
sql_cond - subquery
Other versions: 7.31 | 7.40 | 7.54
Syntax
... ( SELECT result
FROM source
[WHERE sql_cond]
[GROUP BY
group] [HAVING group_cond] ) ...
Effect
A subquery is a SELECT
statement in parenthesis in which all additions except
SINGLE
,
INTO
, and ORDER
BY can be used. Eine Subquery, deren Ergebnismenge einspaltig ist - d.h. die Angabe der Spalten in der SELECT
-Liste in result
der Subquery ist auf eine Spalte oder einen
Aggregatausdruck beschränkt -, bezeichnet man als skalare Subquery.
A subquery can be used within the following relational expressions sql_cond
of the WHERE
conditions for a subquery:
Subqueries can be nested by using subqueries in the WHERE
conditions of a
subquery. In nested subqueries, the columns specified in the WHERE
conditions
are searched inside out, though the columns of inner subqueries conceal columns with the same name in outer subqueries.
A subquery that uses columns from the surrounding SELECT
statement in its
WHERE
condition, is known as a correlated subquery. It must be possible to
assign the column uniquely to a database table or view in the surrounding SELECT
statement. A correlated subquery is evaluated for each individual row of the results set in the surrounding SELECT
statement.
A maximum of ten SELECT
statements are permitted within one Open SQL statement,
in other words the SELECT
statement itself and a maximum of nine other subqueries.
This restriction is independent of whether the subqueries are nested or occur in different relational expressions of the WHERE
condition.
Notes
- Subqueries cannot be used when accessing pooled tables or cluster tables.
- In a correlated subquery, a projection view cannot be accessed in the surrounding
SELECT
statement.
- If a subquery is used, the Open SQL statement bypasses SAP buffering.
- In subqueries that are used in the
WHERE
condition of aDELETE
orUPDATE
statement, there may be no access to the database table to be changed.
- An Open SQL statement must exclusively contain database tables and classic views or exclusively contain CDS entities. A CDS view can only be used together with database tables and classic views, if it is specified as CDS database view.