584. Find Customer Referee
SQL 50 · Select (day 1). Decode it with the hints, solve it on LeetCode, then compare with the reference solution in MySQLPostgreSQL.
Your work
Hints
Open one at a time. Try to finish with as few as you can.
1. What does one output row represent?
One customer.
2. Approach
WHERE referee_id <> 2 OR referee_id IS NULL.
3. The trap
NULL <> 2 is unknown, not true. Customers with no referee vanish without the IS NULL.
Reference solution
Tested on MySQL 8.0 and PostgreSQL 16. Switch dialect at the top of the page.
Show the MySQLPostgreSQL solution
SELECT name
FROM Customer
WHERE referee_id <> 2 OR referee_id IS NULL;Note: PostgreSQL also has WHERE referee_id IS DISTINCT FROM 2, which treats NULL as a normal value.