Using QMF

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.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]