select fields
from tableA --left
left join tableB --right
on tableA.key = tableB.key
The table in the from
in this example tableA
, is on the left side of relation.
tableA <- tableB
[left]------[right]
So if you want to take all rows from the left table (tableA
), even if there are no matches in the right table (tableB
), you'll use the "left join".
And if you want to take all rows from the right table (tableB
), even if there are no matches in the left table (tableA
), you will use the right join
.
Thus, the following query is equivalent to that used above.
select fields
from tableB
right join tableA on tableB.key = tableA.key