183. Customers Who Never Order

Customers Who Never Order - LeetCode

Write an SQL query to report all customers who never order anything. Return the result table in any order.

Input: Customers table:
+—-+——-+
| id | name |
+—-+——-+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+—-+——-+
Orders table:
+—-+————+
| id | customerId |
+—-+————+
| 1 | 3 |
| 2 | 1 |
+—-+————+
Output:
+———–+
| Customers |
+———–+
| Henry |
| Max |
+———–+


  • code
select name as 'Customers' from Customers where id not in (select customerId from Orders)