over 11 years ago
There are two ways to fetch Nth highest salary/number.
1 - By using general sql query which works on all database.
2 - By using database specific sql query.
Database specific sql query example Nth highest salary/number
SQL Queries in Oracle to fetch Nth highest salary/number.
select min(salary) from (select * from (select * from
order by SALARY desc) where rownum < N + 1)SQL Queries in SQL Server to fetch Nth highest salary/number.
select min(SALARY) from (select top N * from
SQL Queries in MySQL to fetch Nth highest salary/number.
select min(SALARY) from (select * from
General sql query to fetch Nth highest salary/number.
SELECT DISTINCT salary FROM emp X WHERE n = ( SELECT COUNT(DISTINCT salary) FROM
Note --
Replace n with the required number to fetch Nth highest salary. for example to get the 3rd highest salary replace n= 3.
Can you help out the community by solving one of the following Manual Testing problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)