RDB/VMS SQL SELECT — VMS RDB_4.2
select-statement = select-expr ─┬─────────────────────────> ──────────┬─>typebox (;) ┌──────────┘ │ └>
O
R
D
E
R
B
Y ─┬┬─> column-name ─┬─┬────>────┬─┬─┐ │ │└─> integer ─────┘ ├─>
A
S
C ──┤ │ │ │ │ └─>
D
E
S
C ─┘ │ │ │ └───────────────<───────────────┘ │ │ ┌────────────────────── <─────────────────────┘ │ └─┬─────────────────────> ────────────────┬─────┘ └>
L
I
M
I
T
T
O ────> row-limit ───>
R
O
W
S ──┘
Additional information available:
More Information
A SELECT statement specifies a result table. A result table is derived from some combination of the tables or views identified in the FROM clause of the statement. The basic element of a SELECT statement is called a select expression. See help on select expressions for more detail. The general form of a SELECT statement is a select expression with an optional ORDER BY clause. In interactive SQL you can issue a SELECT statement by itself or as part of a DECLARE CURSOR statement. In programs, you can include SELECT statements in a DECLARE CURSOR statement (see the section on DECLARE CURSOR). In addition, there is a special form of SELECT statement, called a singleton select, that is legal only in programs. See the online help topic singleton_select for a description of singleton select statements.
select expr
select-expr = ─┬─┬─> select-clause ──────────────┬─┬─┬────────────────────┬─┐ │ ├─>( select-expr ) ─────────────┤ │ └─> order-by-clause ─┘ │ │ └─>( select-expr-standard ) ────┘ │ │ │ ┌─────────<───────────────────────┘ │ │ └─>
U
N
I
O
N ─┬───────┬─────────────┐ │ │ └─>
A
L
L ─┘ │ │ └───────<─────────────────────────┘ │ ┌────────────────────────────────────────────────────────────┘ └─┬────────────────────┬──────────┬────────────────────┬──────> └─> limit-to-clause ─┘ └─> optimize-clause ─┘ See the top-level online help topic select_expr for a description of the select expression.
ORDER_BY
Specifies the order of rows for the result table. SQL sorts the
rows from the intermediate result table by the values of columns
specified in the ORDER BY clause. You can refer to columns in
the ORDER BY clause in two ways:
o By column name
o By column number, where the integer you specify indicates
the left-to-right position of the column in the result table
Select More_Information to continue.
Additional information available:
More Information
You must use an integer to identify a column in the ORDER BY clause if that column in the select list is derived from a function or an arithmetic expression. Whether you identify columns in an ORDER BY clause by name or number, they are called sort keys. When you use multiple sort keys, SQL treats the first column as the major sort key and successive keys as minor keys. That is, it first sorts the rows into groups based on the first column name or value expression. Then it uses the second to sort the rows within each group, and so on. Unless you specify a sort key for every column in the result table, rows with identical values for the last sort key specified are in arbitrary order.
LIMIT_TO
limit-to-clause = ───>
L
I
M
I
T
T
O ────> row-limit ───>
R
O
W
S ──> Specifies the number of rows in the result table. The row limit is a numeric literal. If you specify both a select expression that can be updated and a LIMIT TO clause, the result table can be updated. When specifying a row limit, you cannot use a value expression that refers to a column specification that is a column of the select expression.
ASC
Specifies that the values for sort keys are sorted in ascending order. If you do not specify ASCENDING or DESCENDING for the second or subsequent sort keys, SQL uses the order you specified for the preceding sort key. If you do not specify the sorting order with the first sort key, the default order is ASCENDING.
DESC
Specifies that the values for sort keys are sorted in descending order. If you do not specify ASCENDING or DESCENDING for the second or subsequent sort keys, SQL uses the order you specified for the preceding sort key. If you do not specify the sorting order with the first sort key, the default order is ASCENDING.