select_expression
::=
SELECT [ALL | DISTINCT]
select_listFROM
table_specification,...
[WHERE
search_condition]
[GROUP BY
column,...]
[HAVING
search_condition]
select_list ::= { * | {
table.* |
expression [[AS]
column] } }
The following applies to all clauses:
The clauses must be specified in the given order.
Column names must be unique. If a column name occurs in several tables, you must qualify the column name with the table name. If you rename a table using a correlation name for the duration of the SELECT statement (see section “Table specifications”), you must use only the correlation name.
Example
SELECT o.cust_num, s.service_price
FROM orders o, service s WHERE o.order_num=s.order_num
Evaluation of SELECT expressions
SELECT expressions are evaluated in the following order:
The Cartesian product from all the table specifications in the FROM clause is created.
If a WHERE clause is specified, the WHERE search condition is applied to all the rows of the Cartesian product. The rows for which the search condition returns the value true are selected.
If a GROUP BY clause is specified, the rows determined in point 2 are combined into groups.
If a HAVING clause is specified, the HAVING search condition is applied to all the groups. The groups that satisfy the search condition are selected.
If the SELECT list includes an aggregate function and the derived table has not yet been divided into groups, all the rows in the derived table are combined to form a group.
If the derived table has been divided into (one or more) groups, the SELECT list is evaluated for each group.
If the derived table has not been divided into groups, the SELECT list is evaluated for each derived row.
The resulting rows then form the derived table of the SELECT expression.