Can anyone please explain to me why the following two queries yield different results?
SELECT
o.*
FROM
Customer c
LEFT JOIN
[Order] o ON o.CustomerID = c.CustomerID AND o.OrderType = 'Cash'
WHERE
c.Country = 'USA'
SELECT
o.*
FROM
Customer c
LEFT JOIN
[Order] o ON o.CustomerID = c.CustomerID
WHERE
c.Country = 'USA'
AND
o.OrderType = 'Cash'
Thanks.
The first one allows the order to be NULL, because it’s a left join.
The second one doesn’t, as it checks the value of o.OrderType after the join.
The equivalent would be (assuming OrderType can’t be NULL)