Skip to Main Content
  • Questions
  • Why Oracle has LEFT JOIN and RIGHT JOIN both.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Rajat.

Asked: July 08, 2021 - 1:44 pm UTC

Last updated: July 13, 2021 - 3:31 am UTC

Version: 12.1.0.1

Viewed 1000+ times

You Asked

Hi Tom,

I have been trying to get an answer for a question which says "why does Oracle have both, LEFT and RIGHT OUTER join, when we can solve the purpose by using either of them by exchanging the positions of the tables."

Unfortunately, I didn't find a satisfactory answer for this anywhere, or maybe I didn't find the right place where the answer is available.

Could you please tell me if is there any technical reason for keeping the LEFT and RIGHT outer join separate, or how?

Thanks.

and Connor said...

The main reason is that we need to meet the ANSI standard, which of course has both.

But some other things to think about

- Every subquery can be replaced with a join, but that doesn't mean we should do away with subqueries. They assist with framing a SQL as an answer to a question
- If we only had (say) LEFT, then some times this would mean the table order in the SQL would be less intuitive to the next person who maintains your code
- LEFT and RIGHT are trivial to swap for two tables, but a little less so for more than 1 table, so having both helps
- For those databases without a cost optimizer, the order of the tables in the join can define the execution path, so LEFT and RIGHT are useful.



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, July 09, 2021 - 9:19 am UTC

Perfect!!....this seems logical.

Rajat, July 09, 2021 - 9:21 am UTC

Thanks for the explanation.
Connor McDonald
July 13, 2021 - 3:31 am UTC

glad we could help

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.