Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP - Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT →  SELECT - cond →  WHERE - sql_cond 

sql_cond - subquery

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... ( SELECT result 
            FROM source
             [WHERE sql_cond]
             [GROUP BY group] [HAVING group_cond] ) ...

Wirkung

A subquery is a SELECT statement in parenthesis in which all additions except SINGLE, INTO, and ORDER BY can be used. A subquery with a single-column resulting set, in other words, the specification of the columns in the expression result of the subquery is limited to one column or to an aggregate expression, is known as a scalar subquery.

A subquery can be used within the following logical 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 line of the resulting set in the surrounding SELECT statement.

A maximum of 10 SELECT statements are permitted within one ABAP statement, in other words the SELECT itself and a maximum of 9 other subqueries. This restriction is independent of whether the subqueries are nested or occur in different logical expressions of the WHERE condition.


Notes

  • With 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 a DELETE or UPDATE statement, there may be no access to the database table to be changed.

Continue

sql_cond - ALL, ANY, SOMEsubquery

sql_cond - EXISTS subquery

sql_cond - IN subquery

Subqueries