Can any one tell me whether below 2 queries are an example of Left Outer Join or Right Outer Join??
Table Part:
Name Null? Type
PART_ID NOT NULL VARCHAR2(4)
SUPPLIER_ID VARCHAR2(4)
PART_ID SUPPLIER_ID
P1 S1
P2 S2
P3
P4
Table Supplier:
Name Null? Type
SUPPLIER_ID NOT NULL VARCHAR2(4)
SUPPLIER_NAME NOT NULL VARCHAR2(20)
SUPPLIER_ID SUPPLIER_NAME
S1 Supplier#1
S2 Supplier#2
S3 Supplier#3
Display all the parts irrespective of whether any supplier supplies them or not:
SELECT P.Part_Id, S.Supplier_Name FROM Part P, Supplier S WHERE P.Supplier_Id = S.Supplier_Id (+) SELECT P.Part_Id, S.Supplier_Name FROM Part P, Supplier S WHERE S.Supplier_Id (+) = P.Supplier_Id
TableA LEFT OUTER JOIN TableB
is equivalent toTableB RIGHT OUTER JOIN Table A
.In Oracle,
(+)
denotes the "optional" table in the JOIN. So in your first query, it's aP LEFT OUTER JOIN S
. In your second query, it'sS RIGHT OUTER JOIN P
. They're functionally equivalent.In the terminology, RIGHT or LEFT specify which side of the join always has a record, and the other side might be null. So in a
P LEFT OUTER JOIN S
,P
will always have a record because it's on theLEFT
, butS
could be null.See this example from java2s.com for additional explanation.
To clarify, I guess I'm saying that terminology doesn't matter, as it's only there to help visualize. What matters is that you understand the concept of how it works.
RIGHT vs LEFT
I've seen some confusion about what matters in determining RIGHT vs LEFT in implicit join syntax.
LEFT OUTER JOIN
RIGHT OUTER JOIN
All I did is swap sides of the terms in the WHERE clause, but they're still functionally equivalent. (See higher up in my answer for more info about that.) The placement of the
(+)
determines RIGHT or LEFT. (Specifically, if the(+)
is on the right, it's a LEFT JOIN. If(+)
is on the left, it's a RIGHT JOIN.)Types of JOIN
The two styles of JOIN are implicit JOINs and explicit JOINs. They are different styles of writing JOINs, but they are functionally equivalent.
See this SO question.
Implicit JOINs simply list all tables together. The join conditions are specified in a WHERE clause.
Implicit JOIN
Explicit JOINs associate join conditions with a specific table's inclusion instead of in a WHERE clause.
Explicit JOIN
These Implicit JOINs can be more difficult to read and comprehend, and they also have a few limitations since the join conditions are mixed in other WHERE conditions. As such, implicit JOINs are generally recommended against in favor of explicit syntax.
Those two queries are performing
OUTER JOIN
. See belowTaken from http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/queries006.htm
I saw some contradictions in the answers above, I just tried the following on Oracle 12c and the following is correct :
There is some incorrect information in this thread. I copied and pasted the incorrect information:
The above is WRONG!!!!! It's reversed. How I determined it's incorrect is from the following book:
Oracle OCP Introduction to Oracle 9i: SQL Exam Guide. Page 115 Table 3-1 has a good summary on this. I could not figure why my converted SQL was not working properly until I went old school and looked in a printed book!
Here is the summary from this book, copied line by line:
Oracle outer Join Syntax:
ANSI/ISO Equivalent:
Notice here that it's the reverse of what is posted above. I suppose it's possible for this book to have errata, however I trust this book more so than what is in this thread. It's an exam guide for crying out loud...