Consider a situation where I need a lateral join to get the join
key for a column (say because the values are stored in an array). Then I want to outer join to a fixed list of codes, say to count them. I could write this as:
select c.code, count(u.code)
from codes c left join
(t cross join lateral
unnest(codes) u(code)
)
on c.code = u.code;
Or by using a right join
:
select c.code, count(u.code)
from t cross join lateral
unnest(codes) u(code) right join
codes c
on c.code = u.code;
I still prefer the left join
version, but some might reasonably prefer avoiding parentheses in the from
clause.
If you have only two tables in the from
clause, left join
and right join
are interchangeable; this is not always true when there are more than two tables. I'm not sure if reading direction for the alphabet would affect which outer join someone prefers. I would hypothesize that the underlying grammar of the user's native language might have an effect, perhaps languages where the object precedes the subject; such languages are rather rare, though, and not among the more commonly spoken languages.
RIGHT JOIN
, because they are somehow counter-intuitive (at least for people that read from left to right!). But bottom line that's more a matter of taste, which, to me, qualifies the question as opinion-based.A LEFT JOIN B LEFT JOIN C
can be subtly different fromC RIGHT JOIN B RIGHT JOIN A
depending on the conditions.