We can get the same result in both these ways..
Table_1 LEFT OUTER JOIN Table_2
Table_2 RIGHT OUTER JOIN Table_1
If we can get the same result why to use right outer join ? Which one is better ?
The most substantial difference between the left and right outer join lies in the unmatched records that are obtained besides matched records. The left join takes all matching records and unmatched records of the left table while the right join takes all matching records and unmatched records of the right table.
A LEFT JOIN is absolutely not faster than an INNER JOIN . In fact, it's slower; by definition, an outer join ( LEFT JOIN or RIGHT JOIN ) has to do all the work of an INNER JOIN plus the extra work of null-extending the results.
The main difference between the Left Join and Right Join lies in the inclusion of non-matched rows. Left outer join includes the unmatched rows from the table which is on the left of the join clause whereas a Right outer join includes the unmatched rows from the table which is on the right of the join clause.
TLDR: The most efficient join is also the simplest join, 'Relational Algebra'. If you wish to find out more on all the methods of joins, read further. Relational algebra is the most common way of writing a query and also the most natural way to do so.
As others have pointed out already LEFT OUTER JOIN
and RIGHT OUTER JOIN
are exactly the same operation, except with their arguments reversed. Your question is like asking whether it is better to write a < b
or b > a
. They're the same - it's just a matter of preference.
Having said that, I find that most people are more familiar with LEFT JOIN
and use it consistently in their SQL. Some people even find it quite difficult to read if there is suddenly a RIGHT JOIN
in the middle of a query, and it causes them to have to stop and think what it means. So I'd suggest that given an equal choice between the two options, prefer to use LEFT JOIN
. Being consistent will make it easier for other developers to understand your SQL.
Those are equal, just a matter of preference and readability. I assume its the same tables?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With