Customers Who Never Order

easy hash map database anti join

Problem

Write a SQL query to return the names of customers from Customers who never placed any order in Orders.

SQL: SELECT name AS Customers FROM Customers WHERE id NOT IN (SELECT customerId FROM Orders);

InputCustomers = [(1,Joe),(2,Henry),(3,Sam),(4,Max)]; Orders = [(101,3),(102,1)]
Output["Henry","Max"]

SELECT name AS Customers FROM Customers
WHERE id NOT IN (SELECT customerId FROM Orders);
Time: O(n + m) Space: O(m)