9

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
  • its the same as joining tables a and b, but the on clause is going to reference tables b and c Commented Jul 31, 2012 at 5:35

1 Answer 1

18

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
Sign up to request clarification or add additional context in comments.

7 Comments

yes your solution works any tips for optimisation for this query or this the best solution ready?
This is the best solution. You can help the MySQL server to optimize by adding keys to the table
@yunzen you mean index the fields rite nothing more then rite?
Rite? What do you mean by that?
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.