Outer Join
Description
An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and returns some or all those rows from one table for which no rows from the other satisfy the join condition. (Oracle SQL Language Reference Outer Joins Subsection).
Oracle ANSI syntax
[ query_partition_clause ] [ NATURAL ]
outer_join_type JOIN table_reference
[ query_partition_clause ]
[ ON condition
| USING ( column [, column ]...)
]outer_join_type
{ FULL | LEFT | RIGHT } [ OUTER ]Oracle also supports the (+) operator that can be used to do outer joins. This operator is added to a column expression in the WHERE clause.
Snowflake ANSI syntax
Snowflake also supports the ANSI syntax for OUTER JOINS, just like Oracle. However, the behavior when using the (+) operator might be different depending on the usage. For more information on Snowflake Joins check here.
The Snowflake grammar is one of the following:
Sample Source Patterns
1. ANSI syntax
Snowflake fully supports the ANSI syntax for SQL JOINS. The behavior is the same for both database engines.
Left Outer Join On
Oracle
Snowflake
Right Outer Join On
Oracle
Snowflake
Full Outer Join On
Oracle
Snowflake
2. Natural Outer Join
Both Oracle and Snowflake support the Natural Outer Join and they behave the same.
A NATURAL JOIN is identical to an explicit JOIN on the common columns of the two tables, except that the common columns are included only once in the output. (A natural join assumes that columns with the same name, but in different tables, contain corresponding data.)(Snowflake SQL Language Reference JOIN)
Natural Left Outer Join
Oracle
Snowflake
Natural Right Outer Join
Oracle
Snowflake
3. Basic Outer Join with USING
Table columns can be joined using the USING keyword. The results will be the same as a basic OUTER JOIN with the ON keyword.
Left Outer Join Using
Oracle
Snowflake
4. (+) Operator
Oracle and Snowflake have a (+) operator that can be used for outer joins too. In some cases, Snowflake may not work properly when using this operator.
For more information regarding this operator in Snowflake, check this.
Left Outer Join with (+) operator
Oracle
Snowflake
Right Outer Join with (+) operator
Oracle
Snowflake
Single table joined with multiple tables with (+)
In Oracle, you can join a single table with multiple tables using the (+) operator, however, Snowflake does not support this. Queries with this kind of Outer Joins will be changed to ANSI syntax.
Oracle
Snowflake
Using (+) operator with a column from a not-joined table and a non-column value
In Oracle, you can use the (+) operator with a Column and join it with a value that is not a column from another table. Snowflake can also do this but it will fail if the table of the column was not joined with another table. To solve this issue, the (+) operator is removed from the query when this scenario happens and the result will be the same as in Oracle.
Oracle
Snowflake
Known issues
For all the unsupported cases, please check the related EWIs to obtain recommendations and possible workarounds.
1. Converted Outer Joins to ANSI syntax might reorder de columns
When a query with a non-ANSI Outer Join is converted to an ANSI Outer Join, it may change the order of the columns in the converted query. To fix this issue, try to select the columns in the specific order required.
Oracle
Snowflake
2. Outer joined between predicate with an interval with multiple tables
Between predicates can be used for non-ANSI OUTER JOINS. In Oracle, columns inside the interval can be outer joined, even if they come from different tables, however, Snowflake does not support this. For these cases, the between predicate will be commented out.
Oracle
Snowflake
Related EWIs
SSC-EWI-OR0090: Non-Ansi Outer Join has an invalid Between predicate.
Last updated
