DB2 graphic  QMF Version 8

Subqueries

Subqueries select data from a table. The data is then used to test a condition in the WHERE clause of the main query. For example, this query produces a list of employees who work in the Eastern division:

   SELECT NAME, ID
   FROM Q.STAFF
   WHERE DEPT = SOME
     (SELECT DEPTNUMB            +
     FROM Q.ORG                 |  subquery
     WHERE DIVISION='EASTERN')   +

First, the subquery finds the department numbers in the Eastern division. Then, the main query finds employees who work in any of these departments.

When there are several subqueries, the last one is executed first; the first one is executed last.


Go to the previous page Go to the next page

Downloads | Library | Support | Support Policy | Terms of use | Feedback
Copyright IBM Corporation 1982,2004 Copyright IBM Corporation 1982, 2004
timestamp Last updated: March, 2004