Nesting  Unions

Chapter 9: SQL Derived Tables

Subqueries using SQL derived tables

You can use a SQL derived table in a subquery from clause. For example, this query finds the names of the publishers who have published business books:

select pub_name from publishers
   where "business" in
      (select type from
         (select type from titles, publishers
             where titles.pub_id = publishers.pub_id)
       dt_titles)

Here, dt_titles is the SQL derived table defined by the innermost select statement.

SQL derived tables can be used in the from clause of subqueries wherever subqueries are legal. For more information on subqueries, see Chapter 5, “Subqueries: Using Queries Within Other Queries.”





Copyright © 2005. Sybase Inc. All rights reserved. Unions

View this book as PDF