In the Find Customer Referee interview question, you are given a Customer table with columns id, name, and referee_id. You need to find the names of all customers who were not referred by the customer with id = 2.
This "Easy" SQL question is a classic screening problem used by Apple, Microsoft, and Meta. It tests one specific, vital concept in database management: how to handle NULL values. In SQL, a comparison like referee_id <> 2 will return false for both people referred by ID 2 AND people who have no referee (NULL). It evaluation whether you know to use the IS NULL check.
This is a Filtering problem with NULL logic.
The SQL query requires a WHERE clause that explicitly accounts for both conditions:
WHERE referee_id <> 2 OR referee_id IS NULL.
Table Customer:
| id | name | referee_id |
|---|---|---|
| 1 | Will | NULL |
| 2 | Jane | NULL |
| 3 | Alex | 2 |
| 4 | Bill | NULL |
| 5 | Zack | 1 |
referee_id != 2, which filters out everyone with a NULL referee.NULL is equivalent to an empty string or 0. In SQL, NULL represents an unknown value, and any comparison with it (except IS NULL) results in UNKNOWN."NULL is not a value, it's a state." Always remember that standard comparison operators () fail when one of the operands is NULL. This is the most common pitfall in SQL interviews.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Recyclable and Low Fat Products | Easy | Solve | |
| Customer Who Visited but Did Not Make Any Transactions | Easy | Solve | |
| Article Views I | Easy | Solve | |
| Rising Temperature | Easy | Solve | |
| Big Countries | Easy | Solve |