Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform FULL OUTER JOIN in ORACLE using '+' operator?

Tags:

sql

oracle

Instead of using keywords like FULL OUTER JOIN or FULL JOIN, how can I perform full outer join using 'where' clause with the help of '+' operator?!

like image 828
Munna89 Avatar asked May 08 '12 13:05

Munna89


People also ask

How do you achieve the full outer join in Oracle joins?

The syntax for the Oracle FULL OUTER JOIN is: SELECT columns FROM table1 FULL [OUTER] JOIN table2 ON table1. column = table2.

What is full outer join in Oracle?

What is full outer join in Oracle? A full outer join performs a join between two tables that returns the results of an INNER join as well as the results of a left and right outer join.

Which operator can be used in an outer join condition?

To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join), use the LEFT [ OUTER ] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the join condition in the WHERE clause.

What is the command of full outer join?

The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or right (table2) table records. Tip: FULL OUTER JOIN and FULL JOIN are the same.


1 Answers

You can't (at least directly). Oracle only supports a full outer join using SQL:1999 syntax.

You can fake it by unioning two outer joins:

select a.field1, b.field2
from table_a a, table_b b
where a.id = b.id(+)
union all 
select a.field1, b.field2
from table_a a, table b b
where a.id(+) = b.id
      and a.id is null

It's a lot more readable using the SQL:1999 syntax:

select a.field1, b.field2
from table_a a full outer join table_b b
on a.id = b.id
like image 116
Allan Avatar answered Sep 19 '22 22:09

Allan