DB2 graphic  QMF Version 8

Example 1

This query lists employees whose salaries are greater than their managers' salaries, and selects twice from Q.STAFF.

SELECT X.ID, X.NAME, X.SALARY, Y.SALARY
  FROM Q.STAFF X, Q.STAFF Y
  WHERE X.DEPT = Y.DEPT
    AND Y.JOB = 'MGR'
    AND X.SALARY > Y.SALARY

Selecting twice from Q.STAFF is necessary so that the DEPT of each person can be matched with every other DEPT in the table to discover which employees work for which managers.

The WHERE condition selects employees from both tables who are in the same department, and selects employees in the Y version of the table who are managers. Then, it selects employees whose salaries are greater than their managers' salaries.


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