Returns the result of evaluating the expressions specified after SELECT
.
It can be used in combination with other operations to obtain other effect.
SELECT "Hello, world!";
SELECT 2 + 2;
The SELECT
query result is calculated as follows:
FLATTEN BY
become visible after this point.SELECT
.SELECT
.The standard SQL is sensitive to the order of columns in projections (that is, in SELECT
). While the order of columns must be preserved in the query results or when writing data to a new table, some SQL constructs use this order.
This applies, for example, to UNION ALL and positional ORDER BY (ORDER BY ordinal).
The column order is ignored in YQL by default:
UNION ALL
result is output by column names rather than positionsIf you enable PRAGMA OrderedColumns;
, the order of columns is preserved in the query results and is derived from the order of columns in the input tables using the following rules:
SELECT
: an explicit column enumeration dictates the result order.SELECT
with an asterisk (SELECT * FROM ...
) inherits the order from its input.JOIN
output is undefined, the column order in the result is also undefined.UNION ALL
depends on the UNION ALL execution mode.Results of several SELECT statements (or subqueries) can be combined using UNION
and UNION ALL
keywords.
query1 UNION [ALL] query2 (UNION [ALL] query3 ...)
Union of more than two queries is interpreted as a left-associative operation, that is
query1 UNION query2 UNION ALL query3
is interpreted as
(query1 UNION query2) UNION ALL query3
If the underlying queries have one of the ORDER BY/LIMIT/DISCARD/INTO RESULT
operators, the following rules apply:
ORDER BY/LIMIT/INTO RESULT
is only allowed after the last queryDISCARD
is only allowed before the first queryUNION [ALL]
as a whole, instead of referring to one of the queries