Employee Bonus

You can use a LEFT JOIN between the Employee and Bonus tables to include all employees, even those without a bonus, and then apply a filter to show only the employees with a bonus less than 1000 or no bonus at all.

Here’s the query:

1
2
3
4
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;

Explanation:

  • The LEFT JOIN operation combines the Employee and Bonus tables on the empId column, including all employees even if they don’t have a corresponding entry in the Bonus table.
  • The WHERE clause filters the results to include only rows where the bonus is less than 1000 or is null, meaning the employee does not have a bonus.