Please send questions to
st10@humboldt.edu .
Full Select Statement explanation
* adapted from Sunderraman, "Oracle Programming: A Primer", section 2.4.7,
pp. 53-54
* <sub-select> general form:
select [distinct] <expression> {, <expression>}
from <tablename> [<alias>]{, <tablename> [<alias>]}
[where <search_condition>]
[group by <column> {, <column>}]
[having <condition>]
* <select> general form:
<sub-select>
{union [all] | intersect | minus <sub-select>}
[order by result_column [asc|desc] {, result_column [asc|desc]}
* note that order by clause must come at the end of a select, and since
it really only affects "output", it cannot be in a sub-select;
* important: CONCEPTUAL order of evaluation (may not ACTUALLY be what
SQL uses, because of efficiency/optimization, but you can think of it
this way) (Sunderraman pp. 53-54)
(1) The product of all tables in the from clause [of the
"outer"/initial sub-select] is formed.
(2) The where clause [of the "outer"/initial sub-select] is
evaluated to eliminate rows that do not
satisfy the search_condition.
(3) The rows are grouped using the columns in the group by
clause [of the "outer"/initial sub-select].
(4) Groups that do not satisfy the condition in the having
clause [of the "outer"/initial sub-select]
are eliminated.
(5) The expressions in the select clause target list [of the
"outer"/initial sub-select] are evaluated.
(6) If the distinct keyword is present in the select clause [of
the "outer"/initial sub-select], duplicate
rows are now eliminated.
(7) The union/intersect/minus is taken after each sub-select is
evaluated.
(8) The resulting rows are sorted according to the columns
specified in the order by clause.
* <sub-select> general form:
(6) (5)
select [distinct] <expression> {, <expression>}
(1) from <tablename> [<alias>]{, <tablename> [<alias>]}
(2) [where <search_condition>]
(3) [group by <column> {, <column>}]
(4) [having <condition>]
* <select> general form:
<sub-select>
(7) {union [all] | intersect | minus <sub-select>}
(8) [order by result_column [asc|desc] {, result_column [asc|desc]}
* (and, of course, for each sub-select "connected" by union or
intersect or minus, and for each sub-select buried within a
search-condition, you'd do steps (1)-(6) above.)