Thursday, January 26, 2012

Find the nth highest Salary in a table using MySQL

To find the nth highest salary or highest score in a table, below is the query to find out.

SELECT * FROM employee a WHERE n = (SELECT COUNT(*) FROM employee b WHERE a.salary <= b.salary) ;

'n'  --> By replacing n with the required value we can get the second, third, fourth highest and so on..


1 comment:

tapas said...

thanks for your post