Magicsheet logo

Find Customer Referee

Easy
59.5%
Updated 6/1/2025

Find Customer Referee

What is this problem about?

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.

Why is this asked in interviews?

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.

Algorithmic pattern used

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.

Example explanation

Table Customer:

idnamereferee_id
1WillNULL
2JaneNULL
3Alex2
4BillNULL
5Zack1
  1. Will: referee is NULL. NULL != 2 is "Unknown". Match! (with OR).
  2. Alex: referee is 2. 2 != 2 is False. No match.
  3. Zack: referee is 1. 1 != 2 is True. Match! Final Names: Will, Jane, Bill, Zack.

Common mistakes candidates make

  • Simple Inequality: Using only referee_id != 2, which filters out everyone with a NULL referee.
  • Misunderstanding NULL: Thinking that 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.

Interview preparation tip

"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.

Similar Questions