left join turns into inner join

后端 未结 8 780
爱一瞬间的悲伤
爱一瞬间的悲伤 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:11

    It doesn't turn a LEFT JOIN into an INNER JOIN, thought the effect may appear to be the same. When you set the WHERE condition

    AND c.foobar = 'somethingelse'

    you're getting rid of all the cases that allow a LEFT JOIN TO act as it does. In this case, some of the values for c.foobar will be NULL. Setting this on the JOIN condition still allows non-matching LEFT JOIN results, only restricting what is returned for C results.

提交回复
热议问题