SQL 50, decoded
0 of 50 solved/50

577. Employee Bonus

SQL 50 · Basic Joins (day 2). Decode it with the hints, solve it on LeetCode, then compare with the reference solution in MySQLPostgreSQL.

EasySolve it on LeetCode ↗

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 employee with a bonus under 1000 or no bonus.
2. Approach
LEFT JOIN Bonus, WHERE bonus < 1000 OR bonus IS NULL.
3. The trap
Without IS NULL, employees with no bonus row disappear.

Reference solution

Tested on MySQL 8.0 and PostgreSQL 16. Switch dialect at the top of the page.

Show the MySQLPostgreSQL solution
SELECT e.name, b.bonus
FROM Employee e
LEFT JOIN Bonus b ON e.empId = b.empId
WHERE b.bonus < 1000 OR b.bonus IS NULL;

Patterns used

Which join