less than 1 minute read

Problem

problem-1978

Query

SELECT
    employee_id
FROM
    Employees
WHERE
    manager_id NOT IN (
        SELECT employee_id
        FROM Employees
    ) AND salary < 30000
ORDER BY
    employee_id ASC

LEFT JOIN Approach

SELECT e1.employee_id
FROM Employees e1
LEFT JOIN Employees e2
ON e1.manager_id = e2.employee_id
WHERE e1.salary < 30000 AND e2.employee_id IS NULL AND e1.manager_id IS NOT NULL
ORDER BY employee_id;

Tags:

Updated: