Is it possible to have INNER JOIN and LEFT JOIN together in a SQL query ?
Which join will first execute ? Can you please explain
You can mix inner and outer joins as you need in a query.
The order of execution is irrelevant, that depends on how the optimizer in the DBMS works. The query describes a result set and how that result set is materialised is not governed by the query.
Do you have a specific problem?
If I have multi join ... I find it confusing how the records will be picked up finally
table 1 left join table 2 inner join table3 left join table 4 .....
sorry that is too vague to help you.
If you actually put in an example with sample data to show your concerns someone may be able to help.
Again though, the order the joins are performed in should be irrelevant to the query.
Is there any tool which could help me to do left join and inner join visually together ?
what is it that you are trying to accomplish?
my difficulty is whenever there are multiple inner join and left joins mixed ...I'm confused how the final result will be picked up . I'm stuck at this part.
Is there any thumb rule to remember how the result will be picked up finally ?
Please guide. Thanks
As stated before you can apply the JOINs in any order you wish, the outcome will be the same for all possible orders.
For all intents and purposes you can assume they will be executed from left to right, but this is not necessarily the case as the database will figure out the order itself for each individual query.
In other words
(A JOIN B) JOIN C produces the same result as A JOIN (B JOIN C)
provided you use the same join criteria, of course
- A, B, C can also be JOINs themselves; you can nest this as much as you like.
The only exception I can think of is if you calculate something from two tables and then use that result to join with a third table, in which case the tables that the calculation is based on need to be joined first; this is pretty exceptional though - I can't remember ever doing this and I've been writing queries for 10+ years.
This topic is now archived. It is frozen and cannot be changed in any way.