Derived Tables

Some of the examples from the previous section of this chapter can be solved using subqueries in the FROM clause. Subqueries work as tables in the query, and they are called derived tables. SQL Server considers these subqueries in the same way as ad hoc views, because the definition of the derived tables is merged with the outer query to produce a single query execution plan.

To use a derived table in a query, you must specify in the FROM clause a standard subquery with a table alias for the derived table (see Listing 11.15).

Caution

Correlated queries cannot be used as derived tables.

Code Listing 11.15. You Can Use Derived Tables to Solve Common Queries Without Defining Views or Temporary Tables
					 -- Using a Derived Table to ...

Get Microsoft® SQL Server™ 2000 Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.