Find Top 10 Employees By Salary
Find the top 10 employees by salary without using LIMIT.
sql
SELECT e1.id, e1.name, e1.salary FROM employees e1 WHERE ( SELECT COUNT(*) FROM employees e2 WHERE e2.salary > e1.salary ) < 10 ORDER BY e1.salary DESC;
This query uses a correlated subquery to count how many employees have a higher salary than the current row, filtering for those with fewer than 10 employees earning more, effectively returning the top 10 highest-paid employees.
PromptDB can make mistakes. Please double-check responses.