Skip to content

Conversation

@aryaman0406
Copy link
Owner

PR Title Format: 584.Find Customer Referee.sql

💡 Intuition
The goal is to list the names of all customers except for those whose referee ID is exactly 2. This requires filtering the Customer table based on the referee_id column. We must account for two conditions where a customer should be included in the result:

The referee_id is a number other than 2.

The referee_id is NULL. In SQL, comparing a column to NULL using standard comparison operators (!=, =, etc.) always results in UNKNOWN, which is treated as false in a WHERE clause. Therefore, we must explicitly check for IS NULL.

✍️ Approach
The solution uses a single WHERE clause with an OR condition to filter the rows correctly:

Selection: Select the name column from the Customer table.

Filtering: The WHERE clause includes customers who satisfy either of the following conditions:

referee_id IS NULL: This correctly includes customers who do not have a referee assigned.

referee_id != 2: This correctly includes customers whose referee ID is any value other than 2 (e.g., 1, 3, etc.).

By combining these two conditions with OR, we ensure that the list includes all customers who are either unreferred or referred by anyone other than customer '2'.

Code Solution (SQL)
SQL

SELECT name
FROM Customer
WHERE referee_id IS NULL OR referee_id != 2;
🔗 Related Issues
By submitting this PR, I confirm that:

[x] This is my original work not totally AI generated

[x] I have tested the solution thoroughly on leetcode

[x] I have maintained proper PR description format

[x] This is a meaningful contribution, not spam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants