For this leetcode question: https://leetcode.com/problems/customers-who-never-order/
I know one correct way to solve this is:
SELECT c.name as Customers
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.id = o.customerid
WHERE o.customerid IS NULL;
I want to know why the following does not work:
SELECT c.name as Customers
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.id = o.customerid
WHERE c.id <> o.customerid;
Specifically, WHERE c.id <> o.customerid
or even WHERE c.id NOT IN (o.customerid)
does not work. The NOT IN works when you use a subquery in the where clause but not with a join the way this is written.
Why is that? I want to intuitively understand what's going on.