SQL Interview Questions – Leetcode 577 – Employee Bonus

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s