Find Employees Without Direct Reports

Find employees who have no other employee reporting to them.

sql

SELECT e.id, e.name FROM employees e LEFT JOIN employees m ON e.id = m.manager_id WHERE m.id IS NULL;

This query performs a LEFT JOIN on the employees table with itself, matching employees to their subordinates via a manager_id column, and filters for records where no match is found, indicating the employee has no direct reports.

PromptDB can make mistakes. Please double-check responses.