Find The 3rd Or Nth Highest Salary In A Table Via SubQuery in sql server

Find The 3rd Or Nth Highest Salary In A Table Via SubQuery in sql server

Sample table and data for 2th Highest Salary Problem

CREATE TABLE Employee (name varchar(10), salary int); 
inserting sample data into Employee table INSERT INTO Employee VALUES ('O', 3000);
INSERT INTO Employee VALUES ('A', 5000);
INSERT INTO Employee VALUES ('B', 4000);
INSERT INTO Employee VALUES ('C', 6000);
INSERT INTO Employee VALUES ('D', 8000);
SELECT salary FROM (
    SELECT DISTINCT(salary) FROM employee ORDER BY salary DESC
) WHERE rownum<=3

 

2020-03-05