SQL Interview Questions – Leetcode 577 – Employee Bonus

Spread the love

Problem Description –

Select all employee’s name and bonus whose bonus is < 1000.

Table – Employee

Table – Bonus

Example Output –

Difficulty Level – Easy

Solution –

SELECT 
    e.name,
    b.bonus
FROM Employee AS e LEFT JOIN Bonus AS b
ON e.empId = b.empId
WHERE b.bonus < 1000 OR b.bonus IS NULL 

In this solution including bonus IS NULL along with the bonus < 1000 is important to get the correct answer. You can see in the example output given above in the question. We are also using LEFT JOIN instead of INNER JOIN otherwise John and Brad will be removed from the result.

Rating: 1 out of 5.

Leave a Reply