The examples used in this section are based on the query described below, which uses tables from the SAMPLE database.
Purpose
This query lists the name, department, and earnings for all non-manager employees who earn more than 90% of the highest-paid manager's salary.
Source code
SELECT S.ID,S.NAME,O.DEPTNAME,SALARY+COMM FROM ORG O, STAFF S WHERE O.DEPTNUMB = S.DEPT AND S.JOB <> 'Mgr' AND S.SALARY+S.COMM > ALL( SELECT ST.SALARY*.9 FROM STAFF ST WHERE ST.JOB='Mgr' ) ORDER BY S.NAME
Explanation
The query has two parts:
Because the subquery is qualified by ALL, only the largest value from this table is retrieved.
The main query contains the following three predicates (comparisons):
1. ORG.DEPTNUMB = STAFF.DEPT 2. S.JOB <> 'Mgr' 3. S.SALARY+S.COMM > ALL ( SELECT ST.SALARY*.9 FROM STAFF ST WHERE ST.JOB='Mgr' )
These predicates represent, respectively: