windowsxp — 2012-09-28T03:13:31-04:00 — #1
Is it possible to have INNER JOIN and LEFT JOIN together in a SQL query ?
Which join will first execute ? Can you please explain
swampboogie — 2012-09-28T08:10:03-04:00 — #2
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?
windowsxp — 2012-09-28T09:14:46-04:00 — #3
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 .....
guelphdad — 2012-09-28T09:33:28-04:00 — #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.
windowsxp — 2012-09-28T12:34:25-04:00 — #5
Is there any tool which could help me to do left join and inner join visually together ?
guelphdad — 2012-09-28T13:33:16-04:00 — #6
what is it that you are trying to accomplish?
windowsxp — 2012-09-29T02:56:14-04:00 — #7
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
scallioxtx — 2012-09-29T05:56:31-04:00 — #8
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.
mittineague — 2014-09-18T22:20:04-04:00 — #9
This topic is now archived. It is frozen and cannot be changed in any way.