O'Reilly logo

Microsoft® SQL Server™ 2000 Programming by Example by Carlos Eduardo Rojas, Fernando G. Guerrero

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required