# Find Customer Referee Leetcode Solution

0

Write an SQL query to report the names of the customer that are not referred by the customer with id = 2.

Return the result table in any order.

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| id | int |
| name | varchar |
| referee_id | int |
+-------------+---------+
id is the primary key column for this table.
Each row of this table indicates the id of a customer, their name, and the id of the customer who referred them.

Table: Customer

The query result format is in the following example.

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 |
+------+

Find Customer Referee Leetcode Solution

SELECT name FROM customer
WHERE referee_id !=2 OR referee_id is null

Explanation

This SQL query selects the names of all customers from a table called "customer" where the "referee_id" column does not equal 2 or is null.

In other words, this query selects all customers who were not referred by a customer with ID 2 or who were not referred by anyone (if their referee_id is null).

The query would return a list of customer names who meet the criteria specified in the WHERE clause.

Disclaimer: The above Problem is generated by Leetcode but the Solution is provided by ShouterFolk