Is there a command akin to:
2nd highest salary from tbl_salary
or4th highest salary from tbl_salary
?
I've seen:
select salary
from tbl_salary t
where &n = (
select count(salary)
from(
select distinct salary
from tbl_salary
)where t.salary<=salary
);
How does this it works?
Are there other simple ways to get result?
If it's a basic query, then just use LIMIT:
Description :
limit x,y
Here is a very simple way to get the result of n'th highest value
put n=2 to get second highest salary
pur n=4 to get fourth highest salary
and so on...
Here is query
if n=2
Best luck
You can do it using the limit clause:
// for highest salary of table
// for second highest salary
Using this query you get nth number of salary from table....
I'm sure there is a better way to do this, but:
SELECT salary FROM tbl_salary ORDER BY salary DESC LIMIT n,1
Where n is the position you want - 1 (i.e. to get the second highest salary it would be LIMIT 1,1)