Multiple LEFT JOINs - what is the "left" table? Multiple LEFT JOINs - what is the "left" table? sql sql

Multiple LEFT JOINs - what is the "left" table?


A FROM clause parses the conditions from left to right (unless overridden by parentheses). So:

FROM a LEFT JOIN b     ON foo... LEFT JOIN c     ON bar...

is parsed as:

FROM (        a         LEFT JOIN b           ON foo...     ) LEFT JOIN c     ON bar...

This is explained in the documentation under the join-type section of the FROM clause:

Use parentheses if necessary to determine the order of nesting. In the absence of parentheses, JOINs nest left-to-right. In any case JOIN binds more tightly than the commas separating FROM-list items.

As a consequence, a series of LEFT JOINs keeps all records in the first mentioned table. This is a convenience.

Note that the parsing of the FROM clause is the same regardless of the join type.


It could be both, depending on how you are joining the data (the foo and bars on your example).

For example, if in your example, you want to join a with b and a with c, T1 will be a.

But, if your intention is to join a with b and the result of that with c, then T1 will be a LEFT JOIN b ON foo.

In the last case, would be an improvement on readability if you write like this:

(a LEFT JOIN b ON foo) LEFT JOIN c ON bar


Here is multiple join operation.SQL is a language where you describe the results to get, not how to get them. The optimizer will decide which join to do first, depending on what it thinks will be most efficient. You can read here some information
https://community.oracle.com/thread/2428634?tstart=0
I think, it works the same for PostgreSQL