Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (6.1k points)

I am attempting to get the 3rd highest salary of a table without using limit.

In the case of 2nd highest salary I use

SELECT salary FROM table WHERE salary < ( SELECT MAX( salary ) order by salary desc

To get the 3rd highest with the limit I use

select salary from one order by salary desc limit 3,1

So how can I get the nth salary without using limit?

1 Answer

0 votes
by (12.7k points)
edited by

You can try the following query:

   SELECT *
   FROM one one1
   WHERE ( 3 ) = ( SELECT COUNT( one2.salary )
                   FROM one one2
                   WHERE one2.salary >= one1.salary
                 )

Here WHERE ( n ) you can place any number to return that highest salary.

Want to learn more concepts related to SQL? Join this SQL Course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 4, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Nov 26, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Nov 28, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 17, 2020 in SQL by Appu (6.1k points)

Browse Categories

...