Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When or why would you use a right outer join instead of left?

Wikipedia states:

"In practice, explicit right outer joins are rarely used, since they can always be replaced with left outer joins and provide no additional functionality."

Can anyone provide a situation where they have preferred to use the RIGHT notation, and why? I can't think of a reason to ever use it. To me, it wouldn't ever make things more clear.

Edit: I'm an Oracle veteran making the New Year's Resolution to wean myself from the (+) syntax. I want to do it right

like image 848
DCookie Avatar asked Jan 12 '09 17:01

DCookie


People also ask

When use left outer join and right outer join?

A left outer join is a method of combining tables. The result includes unmatched rows from only the table that is specified before the LEFT OUTER JOIN clause. If you are joining two tables and want the result set to include unmatched rows from only one table, use a LEFT OUTER JOIN clause or a RIGHT OUTER JOIN clause.

Which is better left join or right join?

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.

When would you want to use an outer join?

The FULL OUTER JOIN (aka OUTER JOIN ) is used to return all of the records that have values in either the left or right table. For example, a full outer join of a table of customers and a table of orders might return all customers, including those without any orders, as well as all of the orders.


1 Answers

The only reason I can think of to use RIGHT OUTER JOIN is to try to make your SQL more self-documenting.

You might possibly want to use left joins for queries that have null rows in the dependent (many) side of one-to-many relationships and right joins on those queries that generate null rows in the independent side.

This can also occur in generated code or if a shop's coding requirements specify the order of declaration of tables in the FROM clause.

like image 84
Yes - that Jake. Avatar answered Oct 14 '22 05:10

Yes - that Jake.