DB2 graphic  QMF Version 8

Example 2

This query lists employees who earn the largest commission in each location.

SELECT LOCATION, ID, NAME, COMM
  FROM Q.STAFF, Q.ORG ZZZ
  WHERE DEPT=DEPTNUMB
    AND COMM = (SELECT MAX(COMM)
               FROM Q.STAFF, Q.ORG
               WHERE DEPT=DEPTNUMB
                 AND LOCATION = ZZZ.LOCATION)

In this query, the subquery first finds the largest commission within a given location. The main part of the query finds who within that location earned that commission. Because the query names two tables, it includes a correlation name that indicates which table contains the LOCATION column.


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