how to find nth highest salary
Answers were Sorted based on User's Feedback
Answer / deepak dabi
I Think this is the best solution ever i have seen ,i
appriciate if you prove me wroong on this so,otherwise i got
all other a bit wrong ,in many cases please try this....
"SELECT distinct(sal) from emp order by sal desc limit 2,1"
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / amit
Select salary
from employees
order by salary desc
limit n-1,1;
| Is This Answer Correct ? | 2 Yes | 3 No |
Answer / chandra sekhar
select min(salary) from emp where salary in (select top n salary from emp order by salary desc)
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / anuj somvanshi
select salary from emp where rownum=n order by salary desc;
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / divya
Select Salary
From Employee
Where rowid = n
Order By Salary Desc;
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / lakshmi reddy
To get nth highest salary from Employee table:
select * from Employee e where n=(select COUNT(distinct sal)
from Employee e2 where e2.Sal>e.Sal)
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sharmila shree
SELECT TOP 1 salary FROM
( SELECT DISTINCT TOP 1 salary FROM table_name
ORDER BY salary DESC )
a ORDER BY salary
here 'a' is sub query of salary
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sitakanta rath
SELECT sal FROM
(
SELECT DENSE_RANK() OVER (ORDER BY sal DESC) AS rank, sal
FROM Emp
) T2
WHERE rank=@n
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / ajay kumar barik
select a.id from product a where (1= (select count(b.id)
from product b where b.id>=a.id))
It is for all database
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / ankur bakliwal
I think this should work -
select top 1 salary from employee where salary in (select
distinct
top n salary from employee order by salary desc) order by
salary asc
| Is This Answer Correct ? | 0 Yes | 3 No |
what's the information that can be stored inside a bit column? : Sql server database administration
Explain what is raid and what are different types of raid levels?
What do you understand by replication in sql server? Mention the different types of replication in sql server.
How to add code to the existing article (using improve article)?
what is bit datatype? : Sql server database administration
What is factless fact table? : sql server analysis services, ssas
how to find maximum identity number in a table ?
2 Answers JPMorgan Chase, Thomson Reuters, Wipro,
What is rtm version in sql server?
How do I view a stored procedure in sql server query?
What is the difference between clustered and non-clustered indexes in ms sql server?
Can you explain important index characteristics?
how can you check the level of fragmentation on a table? : Sql server administration
Oracle (3253)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)