Skip to main content
Back to problems
Leetcode
Easy
Hash Maps
Find Customer Referee

Return customers whose referee is not a specific value, while also keeping customers with no referee.

Acceptance 100%
Problem Statement

Problem

You are given a table of customers with at least these columns:

  • id: customer identifier
  • name: customer name
  • referee_id: identifier of the customer who referred them, or NULL if 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_id is anything other than 2, or
  • referee_id is NULL.

Return the result set with the customer names in any order.

Input Format

A Customer table containing customer records with columns similar to:

  • id
  • name
  • referee_id

Output Format

Return one column:

  • name

Constraints

  • referee_id may be NULL.
  • Exclude only customers whose referee_id = 2.
  • The ordering of the output does not matter.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.