I’m a little confused regarding the left and right join operators.
select *
from <left table> lt
left join <right table> rt on lt.pk = rt.fk
I’ve always been a little confused as to exactly which side the “left” side of the join is. The table on the left side of the “left join” keywords … is that “the left table” or is the table on the left side of the on clause the left table as in the one that’s on the left side of the equal sign. I’ve read articles that indicate that it’s supposed to be
However … now considering the following select statement …
select *
from <some table> st
inner join <left table> lt on st.pk = lt.fk
left join <right table r on rt.fk = st.pk
In the above bit of code is the left table ? One would assume so considering the previous statments however because of the ambiguity or the unclarity (because it actually is not directly left) … I would think that it would make more sense for the “left table” to be specified in the on clause.
So every bit of me seems to be fighting that logic … and I need a little bit of clarification … please and thanks.
The first table listed is the one from which all rows will be returned. The table that is named after the
LEFT JOINwill return only rows which match the first table and will return NULL values where no match is found.