How do you exclude a set of values when using a left outer join?
Consider the following query:
SELECT i.id,
i.location,
area.description
FROM incident_vw i,
area_vw area
WHERE i.area_code = area.code(+)
AND i.area_code NOT IN ('T20', 'V20B', 'V20O', 'V20P')
The query executes, yet none of the NULL area code values appear.
BE AWARE: INCIDENT_VW.area_code
can and does have NULL values.
Any ideas on how to match NULL incident area codes while excluding the given set of area codes, without using PL/SQL?
ANSI Update
Using the equivalent ANSI SQL also does not work:
SELECT i.id,
i.location,
area.description
FROM incident_vw i
LEFT JOIN area_vw area
ON area.code = i.area_code
WHERE i.area_code NOT IN ('T20', 'V20B', 'V20O', 'V20P')
Solution
This works:
SELECT i.id,
i.location,
area.description
FROM incident_vw i,
area_vw area
WHERE i.area_code = area.code(+)
AND (i.area_code NOT IN ('T20', 'V20B', 'V20O', 'V20P') and i.area_code IS NULL)
Thanks everyone!