577 Employee Bonus
To find employees with a bonus less than 1000, we need to consider cases where an employee has no bonus at all.
Approach
- Perform a
LEFT JOIN:- We join
EmployeeandBonustables usingempID:
FROM Employee AS e LEFT JOIN Bonus AS b ON e.empID = b.empID- Since
Employeecontains all employees, theLEFT JOINensures that employees without a correspondingBonusrecord will have NULL values in theBonuscolumn.
- We join
- Apply filtering condition:
- We need to select employees where the bonus is either below 1000 or does not exist (NULL):
WHERE b.bonus < 1000 OR b.bonus IS NULL
Conclusion
This ensures that we correctly filter out all employees whose bonus is either below 1000 or who have no bonus at all.