Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


how to find nth highest salary

Answers were Sorted based on User's Feedback



how to find nth highest salary..

Answer / himanshu

Just replace the N with required number:


SELECT empid, empname, empsalary FROM emp e
WHERE (SELECT COUNT(DISTINCT(e2.empsalary))
FROM emp e2
WHERE e2.empsalary >=
e.empsalary ) = N

ex: 4th highest

SELECT empid, empname, empsalary FROM emp e
WHERE (SELECT COUNT(DISTINCT(e2.empsalary))
FROM emp e2
WHERE e2.empsalary >=
e.empsalary ) = 4

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / aravinda

try with this query you will get desired position salary.


Select Salary From Employees a Where 1=(
Select Count(Distinct Salary) From Employees b
Where a.Salary <= b.Salary );

just replace where clause number for desired position. ,2,3,4

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / sanchit dubey

DECLARE @SQL VARCHAR(2000), @N INT
SET @N = 5
SET @N = @N - 1

SET @sql = 'select top 1 salary from ABC where salary not
in ( SELECT TOP ' + CAST(@n AS VARCHAR(100)) + ' salary
FROM ABC order by salary desc ) ' + ' order by salary desc '

SELECT @SQL
EXEC @SQL

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / avinash

declare @n;
set @n = N
select * from tbl
where @n in (
select dense_rank over (order by salary) as rank_sal
from tbl )

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / harshal

Below query is written assuming table "employee" has a column called "salary".
select salary from (select salary from (select distinct(salary) from employee order by salary desc)where rownum<n) order by salary asc where rownum<1;

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / yoursguna@gmail.com

SELECT * FROM `salary_table` group by `salary` order by
`salary` desc limit 1,1

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / nitin munjani

Using Row_Number() function

Here N refers the Nth highest salary

select empid,empname from mstemployee where empsalary in (
(select empsalary from
(select Row_Number() over(order by empsalary desc)
rownm,empsalary from mstemployee
group by empsalary) o where rownm=N))

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / vinay upadhyay

These are tested queries to find Nth highest salary

Select distinct(sal) From employee emp Where n =
( Select Count(Distinct y.sal) From employee y Where y.sal
>=emp.sal)

OR

select distinct(salary) from employee order by salary desc
limit n-1,1

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / ravindra babu

select sal from (select sal from(Select distinct sal from
EMP order by sal desc)Where rownum <=2 order by sal asc)
Where rownum=1;

Is This Answer Correct ?    0 Yes 0 No

how to find nth highest salary..

Answer / sudhir

DISPLAY THE RECORDS WHO'S GETTING 3RD HIGHEST SALARY.

SELECT * FROM EMP E1
WHERE 3 =(SELECT COUNT(DISTINCT(SAL))
FROM EMP E2
WHERE E1.SAL <= E2.SAL)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

How global temporary tables are represented and its scope?

0 Answers  


What is query cost in sql server?

0 Answers  


can foreign key take role of primary key?

5 Answers   CarrizalSoft Technologies, TCS, Villa Marie,


What are the types of subscriptions in SQL Server replication?

0 Answers   HCL,


how to retrive only second row from table in sql server 2000?

15 Answers   Cognizant, CTS,


Difference between Cluster and Non-cluster index?

32 Answers   Accenture, Agility e-Services, eClinicalWorks, HCL, Infosys, Oracle, Satyam, Yardi,


How to find which stored procedure is currently running in sql server?

0 Answers  


Is INSTEAD OF trigger directly applicable to Table ?

0 Answers  


What does it mean to normalize a database and why would you do it?

0 Answers  


Can I remove the default constraint columns in SQL SERVER?

5 Answers   Value Labs,


what is advantages in sql 2005 over sql 2000?

4 Answers  


Explain what is dbcc?

0 Answers  


Categories