Table of Contents
Oracle Database - Effect of a filter on a outer join table
About
When a filter is set on a outer join table, the result is the same that if a inner/equality join was used.
The procedure is as follow:
- The outer join sql return all values and full in the missing values with a NULL value
- The filter on the outer table suppress all records include the NULL values/outer records.
Creation of the example schema
The inner table
CREATE TABLE inner_table AS SELECT object_name FROM all_objects WHERE object_type = 'TABLE' AND rownum < 5
The outer table
CREATE TABLE outer_table AS SELECT object_name, case when rownum < 3 then 'True' else 'False' end STATUS FROM inner_table WHERE rownum < 4
Result
Without the filter on the outer table
nico@gbrdwhs>select 2 inner_table.object_name, 3 STATUS 4 FROM inner_table, 5 outer_table 6 WHERE 7 inner_table.object_name = outer_table.object_name (+); OBJECT_NAME STATUS ------------------------------ ----- DUAL True SYSTEM_PRIVILEGE_MAP True TABLE_PRIVILEGE_MAP False STMT_AUDIT_OPTION_MAP NULL
All objects are present, even the object STMT_AUDIT_OPTION_MAP (which has no parent entry in the outer table) with the value NULL on the STATUS column.
With the filter on the outer table
nico@gbrdwhs>select 2 inner_table.object_name, 3 STATUS 4 FROM inner_table, 5 outer_table 6 WHERE 7 inner_table.object_name = outer_table.object_name (+) 8 AND STATUS = 'True'; OBJECT_NAME STATUS ------------------------------ ----- DUAL True SYSTEM_PRIVILEGE_MAP True
We can see than all records without the True value disappeared and also the record with the NULL value of the outer join.