We have one table say table A we left join with table B. This works fine. The issue here is that based on the left join of table A and B we would like to have another left join but between table B and table C because those fields are available only in this 2 table so what is best solution to build this query?
1 Answer
You can chain joins quite easily:
SELECT ...
FROM a
LEFT JOIN b on a.somefield=b.somefield
LEFT JOIN c on b.otherfield=c.otherfield
7 Comments
user837306
yes your solution works any tips for optimisation for this query or this the best solution ready?
yunzen
This is the best solution. You can help the MySQL server to optimize by adding keys to the table
user837306
@yunzen you mean index the fields rite nothing more then rite?
yunzen
Rite? What do you mean by that?
Marc B
right? simple rule of thumb for indexes: any field used in a join, in a where clause, or an order-by should be indexed. basically anywhere the field is used in a decision-making capacity. |