If you have a LEFT JOIN
and the right table returns nothing (NULL
) all the fields belonging to the right table in the projection are simply NULL
, but you still get your result from the left table. RIGHT JOIN
has the opposite behavior and INNER JOIN
will not return anything.
SELECT * FROM `left_table` LEFT JOIN `right_table`
NULL = NULL
evaluates to UNKNOWN
(which means “no, don’t join because I have no clue if we are allowed to.”) and the projection will only contain the results from the left table.
Of course there are ways to go around this problem:
SELECT *
FROM `left_table` AS `l`
LEFT JOIN `right_table` AS `r`
ON `r`.`id` <=> `l`.`id`
Now checks against NULL
will work normally as you are used to (NULL <=> NULL
is 1
and 'value' <=> NULL
is 0
). Also see the documentation for the equal to operator.