In MySQL online documentation there are some examples with
multi-tables left joins. But all of them are like this (taken from the
documentation):
SELECT ...
FROM table1
LEFT JOIN table2 on (table1.id = table2.id)
LEFT JOIN table3 on (table1.id2 = table3.id2)
LEFT JOIN table4 on (table1.id3 = table4.id3)
Looks pretty. But in every ON clause there is table1, the same which
is in FROM clause. In other words all tables in joins are related to
the same table (table1). I have different situation: table3 is related
to table2 but not to table1. table4 is related to table3 but not to
table1.
Problem: how to constructs joins with such relations? May be part of
the ON clauses content should be put into WHERE clause? But what is
the rule: logic rule or a thumb rule?
Thank you in advance.
Marek Kotowski
Warsaw
multi-tables left joins. But all of them are like this (taken from the
documentation):
SELECT ...
FROM table1
LEFT JOIN table2 on (table1.id = table2.id)
LEFT JOIN table3 on (table1.id2 = table3.id2)
LEFT JOIN table4 on (table1.id3 = table4.id3)
Looks pretty. But in every ON clause there is table1, the same which
is in FROM clause. In other words all tables in joins are related to
the same table (table1). I have different situation: table3 is related
to table2 but not to table1. table4 is related to table3 but not to
table1.
Problem: how to constructs joins with such relations? May be part of
the ON clauses content should be put into WHERE clause? But what is
the rule: logic rule or a thumb rule?
Thank you in advance.
Marek Kotowski
Warsaw
Comment