What is the difference in these two queries as getting two different result set?

后端 未结 6 1049
礼貌的吻别
礼貌的吻别 2020-12-06 14:18

I am getting different result set for these two queries and second result set seems to be correct. What is the difference in these queries.

What type of inner join q

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 14:48

    Looking at the edit history of the question it appears that your queries are along the following lines.

    Query One

      INNER JOIN dbo.T2
            ON ...
        LEFT OUTER  JOIN dbo.T3
            ON  ...
        WHERE 
         T3.col = somevalue AND ...
    

    Query Two

      INNER JOIN dbo.T2
            ON ...
        LEFT OUTER  JOIN dbo.T3
            ON  ... AND T3.col = somevalue
       WHERE 
            ... 
    

    The difference between them is that Query One effectively converts the LEFT Join to an INNER Join.

    For a left outer join conceptually the following happens.

    1. T2 is joined onto T3 and the predicate in the join clause is evaluated.
    2. Any non matching rows from T2 are added back in with NULL values for the T3 column values.
    3. The WHERE clause is applied.

    None of these rows added back in in step 2 will meet the T3.col = somevalue predicate in step 3 as we know that the value of this column for all these rows is NULL.

提交回复
热议问题