13. Non-Referred Customers

A company has a customer referral program, where existing customers can refer new customers to the platform. Each customer record includes the referee_id, which indicates who referred them.

The company maintains a table named Customer to store customer details.

╔═════════════╦══════════╗
║ Column Name ║   Type   ║
╠═════════════╬══════════╣
║     id      ║   int    ║
║─────────────┼──────────║
║    name     ║  varchar ║
║─────────────┼──────────║
║ referee_id  ║   int    ║
╚═════════════╩══════════╝
  • id: A unique identifier (primary key) for the customer table.
  • name: The name of the customer.
  • referee_id: The id of the customer who referred them (can be NULL if they were not referred).

You need to retrieve the names of customers who were NOT referred by customer id = 2. The output can be in any order.

The sample output format is in the following example.

Example 1:

Example 1:

Customer Table:

╔══════════╦══════════╦════════════╗
║    id    ║   name   ║ referee_id ║
╠══════════╬══════════╬════════════╣
║    1     ║  Alice   ║    NULL    ║
║──────────┼──────────┼────────────║
║    2     ║  Daniel  ║    NULL    ║
║──────────┼──────────┼────────────║
║    3     ║  James   ║     2      ║
║──────────┼──────────┼────────────║
║    4     ║  Sarah   ║    NULL    ║
║──────────┼──────────┼────────────║
║    5     ║  Kevin   ║     1      ║
║──────────┼──────────┼────────────║
║    6     ║  Robert  ║     2      ║
╚══════════╩══════════╩════════════╝

Output:

╔══════════╗
║   name   ║
╠══════════╣
║  Alice   ║
║──────────║
║  Daniel  ║
║──────────║
║  Sarah   ║
║──────────║
║  Kevin   ║
╚══════════╝

Explanation:

  • Alice, Daniel, Sarah, and Kevin are included in the output because they were not referred by customer id = 2.
  • James and Robert are excluded because they were referred by customer id = 2.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
 
Test Case

Input:

Customer