This topic describes subqueries that occur as nested SELECT
statements in the FROM clause of an outer SELECT statement. Such subqueries
are sometimes called derived tables or table expressions because
the outer query uses the results of the subquery as a data source.
The
following query uses asterisk notation in the outer query to return
the results of a subquery that retrieves all fields of the address column
in the employee table.
This illustrates how to specify a derived table, but
it is a trivial example of this syntax, because the outer query does
not manipulate any values in the table expression that the subquery
in the FROM clause returns. (See Query for a simple
query that returns the same results.)
The following query is a more complex example in which
the outer query selects only the first qualifying row of a derived
table that a subquery in the FROM clause specifies as a simple join
on the customer and cust_calls tables.
The query returns only those rows in which the customer
has made a call to customer service, as the result shows.
In the preceding example, the subquery includes an ORDER
BY clause that specifies a column that appears in Projection list
of the subquery, but the query would also be valid if the Projection
list had omitted the u.call_dtime column. The FROM clause is
the only context in which a subquery can specify the ORDER BY clause.