The NOT IN Trap With NULL
Medium
NULL Handling
Return the ids of customers who have never placed an order. The Orders table contains a row whose customer_id is NULL, so a naive NOT IN returns nothing. Write a query that returns the correct result. Order by id.
Table schema
Customers(id INT PRIMARY KEY, name VARCHAR(50))
Orders(id INT PRIMARY KEY, customer_id INT NULL)Sample data
Customers ids: 1, 2, 3
Orders:
id | customer_id
1 | 1
2 | NULL
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.