Is Order of Joins important if there are
- multiple joins
- 3rd join depends on 2nd join (lets assume and is the case in this question)
I am unable to come to conclusion on this. I had multiple queries with the above criteria. Some of them seem to work, some are not producing proper result (not sure if its because of joins), some actually throw error.
Anyone has any specific Idea on this?
Order of joins is important if you are using OUTER joins in your query (
LEFT OUTER JOIN,RIGHT OUTER JOIN,LEFT JOIN, orRIGHT JOINnotation).If you’re only using all INNER joins, it should not matter as long as they all relate to each other via some chain of ON conditions. This hold true whether you have 3 or 30 inner joins linked together.
The query optimizer will juggle them around anyhow based on the optimal execution plan based on indexes and such.