<aside> 💡
This project demonstrates the ability to query and manipulate relational databases effectively by solving a real-world business problem. The objective was to identify employees with salaries below $30,000 whose managers have left the company, providing insights into the workforce structure.
</aside>
The Employees table contains the following information:
manager_id is NULL, the employee does not have a manager.Managers who leave the company have their records removed from the table. However, the employees they manage retain their manager_id, pointing to the removed manager.
The task was to find all employees:
The results were to be ordered by employee_id.
The query utilizes SQL to identify the required employees by leveraging subqueries and filtering conditions:
SELECT e.employee_id
FROM Employees e
WHERE e.salary < 30000
AND e.manager_id NOT IN (SELECT e.employee_id FROM Employees e)
ORDER BY e.employee_id;
WHERE e.salary < 30000 ensures only employees earning less than $30,000 are considered.