SQL problem - Customers Who Never Order
Problem
Query
SELECT c.name as Customers
FROM Customers AS c
WHERE c.id NOT IN (
SELECT customerId
FROM Orders
)
Editorial Solution
Approach 1: Filtering Data with Exclusion Criteria
select *
from customers
where customers.id not in
(
select customerid from orders
);
Approach 2: Left Join on customers
SELECT name AS 'Customers'
FROM Customers
LEFT JOIN Orders ON Customers.Id = Orders.CustomerId
WHERE Orders.CustomerId IS NULL