<aside> 💡

Project Overview:

This project identifies employees with bonuses less than 1000 or no bonus at all. The task demonstrates the use of SQL joins, conditional filtering, and handling NULL values.

</aside>


Problem Description:

Tables:

  1. Employee:
  2. Bonus:

The objective is to find the name and bonus of employees whose bonus is less than 1000 or who do not have a bonus (NULL).


Solution:

The query combines the Employee and Bonus tables using a LEFT JOIN to include all employees, even if they do not have a bonus, and filters the results based on the given conditions.

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


Explanation:

  1. Joining Tables:
  2. Filtering Conditions:
  3. Selecting Columns:

Example Input and Output:

Input:

Employee Table: