Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 left join but I don't know how to do it when the query involves more than two tables like in this case.

like image 635
aleafonso Avatar asked Nov 02 '11 12:11

aleafonso


People also ask

Can you left join more than 2 tables?

Sometimes you need to LEFT JOIN more than two tables to get the data required for specific analyses. Fortunately, the LEFT JOIN keyword can be used with multiple tables in SQL.

How join multiple tables with LEFT join?

Syntax For Left Join:SELECT column names FROM table1 LEFT JOIN table2 ON table1. matching_column = table2. matching_column; Note: For example, if you have a left table with 10 rows, you are guaranteed to have at least 10 rows after applying join operation on two tables.


1 Answers

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
like image 122
Chris J Avatar answered Sep 30 '22 07:09

Chris J