Return customers whose referee is not a specific value, while also keeping customers with no referee.
Problem
You are given a table of customers with at least these columns:
id: customer identifiername: customer namereferee_id: identifier of the customer who referred them, orNULLif they were not referred
Write a query to return the names of customers who were not referred by the customer with id = 2.
A customer should be included if:
referee_idis anything other than2, orreferee_idisNULL.
Return the result set with the customer names in any order.
Input Format
A Customer table containing customer records with columns similar to:
idnamereferee_id
Output Format
Return one column:
name
Constraints
referee_idmay beNULL.- Exclude only customers whose
referee_id = 2. - The ordering of the output does not matter.
Example 1
Input
Customer table +----+------+------------+ | id | name | referee_id | +----+------+------------+ | 1 | Will | null | | 2 | Jane | null | | 3 | Alex | 2 | | 4 | Bill | null | | 5 | Zack | 1 | | 6 | Mark | 2 | +----+------+------------+
Output
+------+ | name | +------+ | Will | | Jane | | Bill | | Zack | +------+
Explanation
Exclude customers whose referee is 2. Keep rows where referee_id is NULL or any value other than 2.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.