left join turns into inner join

后端 未结 8 784
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 06:24
SELECT
a.foo
b.bar
c.foobar
FROM tableOne AS a
INNER JOIN tableTwo AS b ON a.pk = b.fk
LEFT JOIN tableThree AS c ON b.pk = c.fk
WHERE a.foo = \'something\'
AND c.foo         


        
8条回答
  •  暖寄归人
    2020-11-29 07:17

    1st case (where the c.foobar is in the where clause) the filtering by the c.foobar happens after the joins have occured (they occur correctly), so you effectively filter-out all resulting records that do not have a 'somethingelse' in there..

    2nd case the c.foobar is part of the join, so it evaluates at joining time and just controls the output of the join, and not the final recordset (returnsnull where the join fails)..

提交回复
热议问题