aleafonso aleafonso - 1 year ago 51
MySQL Question

How to do LEFT JOIN with more than 2 tables?

Currently I am doing this query:

select a.x, b.x, c.x
from number as a, customer as b, numbergroup as c
where a.b = b.b and a.c = c.c and c.b = b.b


However, I want to retrieve records from table "a" even if "a.c = null", which is not retrieved due to the join between "a" and "c".

I have found information about the "left join" (http://www.w3schools.com/sql/sql_join_left.asp) but I don't know how to do it when the query involves more than two tables like in this case.

Any help or guidance will be greatly appreciated.

Answer Source
select a.x, b.x, c.x 
from number as a
left join customer as b on a.b = b.b
left join numbergroup as c on a.c = c.c and c.b = b.b