Finding intersection and difference with exists  Using correlated subqueries

Chapter 5: Subqueries: Using Queries Within Other Queries

Subqueries using SQL derived tables

A SQL derived table can be used 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 SQL derived tables, see Chapter 9, “SQL Derived Tables.”





Copyright © 2005. Sybase Inc. All rights reserved. Using correlated subqueries

View this book as PDF