Examples:

The first example is: Select DEPT, NAME, SALARY from Q.STARR CORRVAR
where SALARY = (Select MAX(SALARY) from Q.STAFF where DEPT = CORRVAR.DEPT).
The subquery is (Select MAX(SALARY) from Q.STAFF where DEPT = CORRVAR.DEPT).
The second example is: Select ID, NAME from Q.STAFF where DEPT in
(Select Distnct DEPTNMUB from Q.ORG where DIVISION = 'MIDWEST') Order by ID.
The subquery is (Select Distnct DEPTNMUB from Q.ORG where DIVISION = 'MIDWEST'.
The third example is: Select DEPT, Avg(SALARY) from Q.STAFF Group by DEPT
having Avg (SALARY) > (Select Avg(SALARY) from Q.STAFF. The subquery is (Select
Avg(SALARY) from Q.STAFF.
   SELECT DEPT, AVG(SALARY)
   FROM Q.STAFF
   GROUP BY DEPT
   HAVING AVG(SALARY) >
      (SELECT AVG(SALARY) FROM Q.STAFF)  ]  subquery
[ Previous Page | Next Page | Contents | Index ]