This is the one of the most common question asked in SQL.
"How to find Nth highest or lowest salary in SQL"
If you find the answer using the "TOP" keyword
Than interviewer ask you can you find out with other way
so i will tell to some step including the top
But before start we need one employee table it is as below
1. To get max salary from Employee table.
2. To get salary using Top.
SELECT TOP 1 Salary AS 'Higest Salary',Name FROM (SELECT DISTINCT TOP 3 Salary,Name FROM tblSalary ORDER BY Salary DESC) a ORDER BY Salary ASC
"How to find Nth highest or lowest salary in SQL"
If you find the answer using the "TOP" keyword
Than interviewer ask you can you find out with other way
so i will tell to some step including the top
But before start we need one employee table it is as below
1. To get max salary from Employee table.
SELECT MAX(salary) FROM employee;
2. To get salary using Top.
SELECT TOP 1 Salary AS 'Higest Salary',Name FROM (SELECT DISTINCT TOP 3 Salary,Name FROM tblSalary ORDER BY Salary DESC) a ORDER BY Salary ASC
No comments:
Post a Comment