SELECT - select_clause
... [DISTINCT] select_list ...
SELECT clause of a
query statement. The
SELECT defines the structure of the results set
SELECT statement. It consists of a
SELECT list, which defines the columns of the results set, and an optional addition
DISTINCT, which removes duplicative rows from the results set.
can indicate all columns of a data source using
* or it defines the individual columns of the results set using an
SQL expression. It defines the names of the columns in the results set, using optional or mandatory alias names.
SELECT clause must either be listed as the first clause after the keyword
SELECT (or after the optional addition
or after the
FROM clause. After the
the SELECT clause must be introduced using the addition
FROM clause of the
SELECT clause supports tools such as the code completion in ABAP Editor.
SELECT clause after
SELECT list specifies individual columns plus aggregate expressions as arguments using SQL expressions.
SELECT FROM sflight FIELDS carrid, connid, MAX( seatsmax - seatsocc ) AS seatsfree_max, MIN( seatsmax - seatsocc ) AS seatsfree_min GROUP BY carrid, connid HAVING carrid = 'LH' INTO TABLE @DATA(result).
DISTINCT removes rows that occur more than once in a multirow results set. Here the entire row content is taken into consideration.
DISTINCT must not be used in the following cases:
If the addition
If a column specified in the
select_listhas the type STRING, RAWSTRING, LCHR, LRAW, or GEOM_EWKB.
DISTINCT is used, the statement
SELECT bypasses table buffering.
For the addition
DISTINCT, it is not important which columns of the results set are key fields of the associated database tables, views, or CDS entities.
The comparison is based on the full row content, which means that the number of rows in the results
set is determined by the
SELECTlist. If, for example, all key fields of a database table are specified directly as
columnsin a SELECT list, there can be no rows that occur more than once. The other extreme is the case where a
SELECTlist contains a single host variable or a single literal. Here, all rows are deleted except one.
As a part of the
SELECTclause, the addition
DISTINCTis applied before the additions UP TO and
DISTINCTis specified, it should be noted that this requires the execution of sort operations in the database system, and the statement
SELECTtherefore bypasses table buffering.
Gets all destinations to which Lufthansa flies from Frankfurt.
SELECT DISTINCT cityto FROM spfli WHERE carrid = 'LH' AND cityfrom = 'FRANKFURT' INTO TABLE @DATA(destinations). cl_demo_output=>display( destinations ).