|
I found different results using below queries I need to understand why does position of
(comments are locked)
|
|
The point that both @Fatherjack and @Scot Hauder are trying to make is that an INNER JOIN uses the join predicates to actively filter out the entire result set. The matching data from both sides of the join will be returned and nothing else. An OUTER JOIN on the other hand takes the data from the "driving" table (TableA in your example) and joins to TableB using the join predicate you specify and tries to collect matching data for the entire selected set of TableA. If there is no corresponding data in TableB you get NULLs returned in place of data for TableB. If you add additional ANDs to an INNER JOIN it doesn't matter if they are in the JOIN or in the WHERE section of the query. They equate to the same filtering operation in the end so the Query Optimizer will generate the same plan for both ways. If you add additional ANDs to an OUTER JOIN, placing it in the JOIN will change how the outer table (TableB) is joined and probably just increase the amount of NULLs produced. If you move the same AND down to the WHERE clause, you will find that your result set will be filtered according to the entire WHERE clause and end up with less rows than if you had the AND in the JOIN. +1. I think you nailed the explaination.
Aug 16 '12 at 10:30 AM
Magnus Ahlkvist
(comments are locked)
|
|
In the first you are saying and in the second So, firstly rows are filtered by the join between C and B where the columns match AND B.COLC has to be in the options whereas in the last option returns rows where the join on B and A matches AND B.COLC is in the list of options. These are two very different queries. Jonathan thanks for the answer but i didn't quite follow your explanation. Do you think you/someone can explain me with an example (with data) so that it would be easy for me to understand? I appreciate your help.
Aug 15 '12 at 05:17 PM
visrah
(comments are locked)
|
|
Another example may drive the point home. When using outer joins you need to be mindful of what is in the JOIN condition and what is in the WHERE clause. With INNER joins this is not an issue:
(comments are locked)
|

