Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query to find Nth highest salary from a salary table

Tags:

mysql

some one help me to find out nth highest salary from the salary table in MYSQL

like image 386
jauwad Avatar asked Aug 02 '12 06:08

jauwad


People also ask

How can we find nth highest salary in each department in SQL Server?

The NTH_VALUE() function explicitly shows you the value of the third-highest salary by department. The ROW_NUMBER() , RANK() , and DENSE_RANK() functions rank the salaries within each department. Then, you can simply find the salary value associated with rank number 3.

What is nth highest salary?

Step 2: Find the nth highest salary We will use the min function and the limit keyword. The nth highest salary is the minimum salary among the top n rows of A . The min function returns the minimum value for a column in a table. The limit function returns the first n rows.


1 Answers

Try this, n would be the nth item you would want to return

 SELECT DISTINCT(Salary) FROM table ORDER BY Salary DESC LIMIT n,1
like image 72
babooney Avatar answered Nov 14 '22 23:11

babooney