Find Customer Referee - Problem
Given a Customer table with customer information and referral relationships, find the names of customers who are either:
- Not referred by customer with id = 2 (referred by any other customer)
- Not referred by any customer (referee_id is NULL)
Return the result table in any order.
Table Schema
Customer
| Column Name | Type | Description |
|---|---|---|
id
PK
|
int | Primary key - unique customer identifier |
name
|
varchar | Customer name |
referee_id
|
int | ID of the customer who referred this customer (can be NULL) |
Primary Key: id
Note: Each row represents a customer and their referrer. referee_id can be NULL if no referrer exists.
Input & Output
Example 1 — Basic Filtering
Input Table:
| id | name | referee_id |
|---|---|---|
| 1 | Will | 2 |
| 2 | Jane | |
| 3 | Alex | 1 |
| 4 | Bill | |
| 5 | Zack | 1 |
Output:
| name |
|---|
| Jane |
| Alex |
| Bill |
| Zack |
💡 Note:
Will is excluded because he was referred by customer with id = 2. Jane and Bill are included because they have no referrer (NULL). Alex and Zack are included because they were referred by customer with id = 1 (not 2).
Example 2 — All NULL Referees
Input Table:
| id | name | referee_id |
|---|---|---|
| 1 | Alice | |
| 2 | Bob |
Output:
| name |
|---|
| Alice |
| Bob |
💡 Note:
Both customers have no referrer (referee_id is NULL), so both are included in the result since they were not referred by customer with id = 2.
Constraints
-
1 ≤ Customer.id ≤ 1000 -
Customer.nameconsists of uppercase and lowercase letters -
referee_idcan beNULLor reference another customer's id
Visualization
Tap to expand
Understanding the Visualization
1
Input
Customer table with referral data
2
Filter
Exclude referee_id = 2, include NULLs
3
Output
Names of filtered customers
Key Takeaway
🎯 Key Insight: Always handle NULL values explicitly when using comparison operators in SQL WHERE clauses
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code