In the below two queries, it produces two different results. I understand HOW sql will process this, but I want to confirm my interpretation of WHY it functions like this is accurate.Select * from #InfoTable aleft join #COMPUTEFields bon a.EmployeeID = b.EmployeeID and a.PlanID = b.PlanIDWhere a.Typeidentifier = 0Select from #InfoTable aleft join #COMPUTEFields bon a.EmployeeID = b.EmployeeID and a.PlanID = b.PlanIDand a.Typeidentifier = 0
I know how this works, but can someone explain WHY this works this way? Shouldn't a filter on the join of "And a.TypeIdentifier = 0" filter out the first table as well since it is explicitly being instructed to, or is it just simply because it's a left join, that anything in that join clause only pertains to the right table?Now let's take the argument one step further. Select from #InfoTable aInner join #ANOTHERTABLE bbon a.EmployeeID = bb.EMployeeIDand a.Typeidentifier = 0--Filters fine above since SQL knows that a inner join is checking--Both tablesSelect from #InfoTable aInner join #ANOTHERTABLE bbon a.EmployeeID = bb.EmployeeIDand a.Typeidentifier = 0left join #COMPUTEFields bon a.EmployeeID = b.EmployeeID and a.PlanID = b.PlanID--Here it does not filter anymore, because once a Left Join is--introduced on table a, it now no longer will filter
So again even with a inner join as long as that left join is present, there is NO filtering on that first table in the join syntax, it needs to be in the where. But in the last query to me it seems like since the inner join exists that it SHOULD filter "a.Typeidentifier = 0". It would've if I wrote asSelect from #InfoTable aInner join #ANOTHERTABLE bbon a.EmployeeID = bb.EmployeeIDand a.Typeidentifier = bb.TypeIdentifierleft join #COMPUTEFields bon a.EmployeeID = b.EmployeeID and a.PlanID = b.PlanID
Why didn't Microsoft write the SQL engine to factor in a explicit left table filter when there is a left join, it is not crystal clear to me? I understand there is a legitimate reason, but I would like to know it if someone could explain?Thanks!
Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881