Please have a look at the tables below:
Customer Table:
ID
Name
Order Table:
ID
CustomerID
A customer can place 0,1 or many orders. Please have a look at the SQL query below:
SELECT Customer.*
FROM Customer LEFT JOIN Order ON Customer.ID=Order.CustomerID
WHERE CustomerID IS NULL
and
SELECT Customer.*
FROM Customer LEFT JOIN Order ON Customer.ID=Order.CustomerID AND
CustomerID IS NULL
Is there any difference between these two queries? When would a developer use one technique rather than the other?
I thought there would be other questions like this online, but I have not found the answer and hence the reason for the question.
In terms of result set and query plans the two are likely to produce identical results.
In that respect, they are the same.
If talking about readability, I would use the
WHEREversion, as the join condition is explicit and theWHEREclause is explicit to what results to include/exclude.