Find Employees With Higher Department Salaries

Find employees whose salary is higher than at least one employee in another department.

sql

SELECT DISTINCT e1.id, e1.name, e1.salary, e1.department_id FROM employees e1 WHERE e1.salary > ( SELECT MIN(e2.salary) FROM employees e2 WHERE e2.department_id <> e1.department_id );

This query identifies employees whose salary exceeds the minimum salary of any employee belonging to a different department by using a correlated subquery to compare the individual's salary against the minimum salary of all other departments.

PromptDB can make mistakes. Please double-check responses.