how to find nth highest salary
Answers were Sorted based on User's Feedback
Answer / ganesh prasad
all are not working properly incase repeat salary
this one is correct to finding 4th highest salary try run
your system then call me 9438183722
select min(deptsal) from dept where deptsal in ( select
distinct top 4 deptsal from dept order by deptsal desc)
| Is This Answer Correct ? | 5 Yes | 14 No |
Answer / sysdomain
'top' will fetch only top most : ie top 5 means it will
fetch first 5 rec. After fetching rec only 'order by' is
done ie sorting is done after fetching. therefore using
'top' and 'order by' alone wont get max or min value. for
that we have to use 'distinct' before 'top' (which will sort
the records before fetching).
select top 1 salary from employee where salary in (select
distinct
top n salary from employee order by salary desc)
| Is This Answer Correct ? | 7 Yes | 16 No |
Answer / saurabh
select max(salary) from Employee where salary not in (
select top 5 Salary from ( select distinct Salary from
Employee order by Salary desc))
| Is This Answer Correct ? | 0 Yes | 11 No |
Answer / vijay dev arya
select salary from employee where salary>(select max
(salary) from employee)
| Is This Answer Correct ? | 6 Yes | 17 No |
Answer / smitam
select top 1 salary from emp where (salary<(select max
(salary) from emp ))ORDER BY salary DESC
| Is This Answer Correct ? | 9 Yes | 21 No |
Answer / vijay
select top 1 sal
from
(select top 3 sal
from emp
order by sal desc )sub
order by sal
| Is This Answer Correct ? | 12 Yes | 24 No |
SELECT TOP Nth salary
FROM (
SELECT TOP N salary
FROM emp
ORDER BY salary DESC
) TmpTable
ORDER BY salary ASC
| Is This Answer Correct ? | 38 Yes | 56 No |
Answer / pandian
select top 1 salary from (select distinct top 9 salary from
EmpMaster order by salary desc)a
| Is This Answer Correct ? | 65 Yes | 88 No |
Answer / kavitha. r
select top 1 salary from employee where salary in (select
top n salary from employee order by salary desc) order by
salary desc
| Is This Answer Correct ? | 12 Yes | 40 No |
Tell me what are the essential components of sql server service broker?
can an order by clause be used in a creation of a view?
What are the ways available in sql server to execute sql statements?
About Indexed Views? with example? plz reply...
How to create user defined functions with parameters?
Explain about temporary stored procedure?
What is indexed view? How to create it?
What is MSDE?
What is set nocount on?
What is the maximum number of instances in 32 bit and 64 bit sql server 2012?
How are SQL Server databases physically stored under Windows 2000?
What are actions, how many types of actions are there, explain with example? : sql server analysis services, ssas
Oracle (3259)
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)