Home > Software engineering >  Find third highest salary of employee without order by and limit
Find third highest salary of employee without order by and limit

Time:03-26

Find third highest salary of employee without order by and limit.

 select(SELECT MIN(Salary)
    FROM   (SELECT * TOP (3) Salary
           FROM   Employees
           )

Not working in the mysql work bench

CodePudding user response:

You can try this -

SELECT salary 
FROM Employees e1
WHERE 3-1 = (SELECT COUNT(DISTINCT salary) FROM Employees e2
WHERE e2.salary > e1.salary)

CodePudding user response:

Try this:

WITH emp (
    SELECT 
        ROW_NUMBER() OVER (ORDER BY salary DESC) rowId, * 
    FROM employee
) 
SELECT * FROM emp WHERE rowId = 3;
  • Related