SQL$HELP_OLD72.HLB  —  User Supplied Names, Column Names, Outer References
    You may have to qualify column names in an outer reference.
    An outer reference is a reference within a subquery to a table
    specified in an outer query that contains the subquery. An outer
    reference is also called a correlated reference.

    For example, the previous example that retrieved the names
    of employees who worked in the marketing department can be
    reformulated to use an outer reference.

    SQL> SELECT    FIRST_NAME,                              --
    cont>           LAST_NAME                               --
    cont>   FROM    EMPLOYEES                               --
    cont>   WHERE   'MKTG' IN                               --
    cont>           (SELECT DEPARTMENT_CODE         --       -- Outer
    cont>            FROM   JOB_HISTORY             --       -- Query
    cont>            WHERE  JOB_END IS NULL         -- Sub-  --
    cont>                   AND                     -- query --
    cont>                   EMPLOYEE_ID =
    cont>                   EMPLOYEES.EMPLOYEE_ID)  --       --
    cont> --                ---------------------
    cont> --                  outer reference
    cont> ;
     FIRST_NAME   LAST_NAME
     Chris        Danzig
     Lawrence     Hall
     Paul         Belliveau
    3 rows selected

    If the outer reference to EMPLOYEE_ID in this example were not
    qualified by the table name EMPLOYEES, it would refer to the
    EMPLOYEE_ID column in the subquery, not the outer query. The
    predicate EMPLOYEE_ID = EMPLOYEE_ID is true for all values
    of EMPLOYEE_ID that are not null, so the statement would not
    generate an error, but would give unexpected results. Instead of
    the three marketing employees, it would select all rows of the
    EMPLOYEES table with values in the EMPLOYEE_ID column that were
    not null.

    Although the outer reference is contained within a subquery,
    it receives its value from an outer query. Because of this,
    the subquery must be evaluated once for each value that the
    outer reference receives from the outer query. It is this
    characteristic that defines an outer reference.
Close Help