Subqueries

A subquery is just a query contained inside another query. You can call the subquery an inner query contained within an outer query, which in turn can be a standard query or another subquery.

If you think about standard queries, you can define three kinds of queries, according to the type of result they provide:

  • Scalar—Queries that produce a single value (one single row with only one column)

  • List—Queries that produce a list of values (one or more rows with a single column only)

  • Array—Queries that return a result set (one or more rows with one or more columns)

List queries can be considered single-column array queries. Scalar queries can be used as single-column, single-row array queries as well.

Listing 11.1 shows different scalar queries ...

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.