Correlated Subqueries

What is a correlated subquery ?
A correlated subquery is a SELECT statement nested inside another SELECT
statement where the inner query contains a reference to one or more
columns in the outer query. Therefore, the correlated subquery can be
said to be dependent on the outer query. This dependency is the
difference between a correlated subquery and a plain subquery. A plain
subquery is not dependent on the outer query, can be run independently
of the outer query, and will return a result set. A correlated
subquery, because it depends on the outer query, will return a syntax
errors if run by itself.
SELECT EMPNO, LASTNAME, WORKDEPT, EDLEVEL
   FROM CORPDATA.EMPLOYEE X
   WHERE EDLEVEL >
      (SELECT AVG(EDLEVEL)
         FROM CORPDATA.EMPLOYEE
         WHERE WORKDEPT = X.WORKDEPT)

1 Comment »

  1. rafi said

    hi send me tough questions

RSS feed for comments on this post · TrackBack URI

Leave a Comment