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 / saravanan

The below 2 queries will work
n - The nth highest salary

First query
------------------------
SELECT MAX(salary)
FROM
(SELECT salary
FROM emp
WHERE salary IS NOT NULL
ORDER BY salary DESC)
WHERE rownum < &n;

Second query
------------------------
SELECT DISTINCT(a.salary)
FROM emp a
WHERE &n =
(SELECT COUNT(DISTINCT(b.salary))
FROM emp b
WHERE a.salary <= b.salary)
;

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / parmesh m

select top 1 salary from Employee where salary in (
select top n salary from Employee
group by salary
having count(salary )< n+1
order by salary desc )
order by salary

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / kalai

SELECT * FROM EMP A WHERE 7=(SELECT COUNT(SAL) FROM EMP
WHERE A.SAL<SAL)

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / sanwar hudda

n th Highest salary

select salary from test t1 where n-1=(select COUNT (*) from
test

where salary > t1.salary )

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / sikindar

select * from emp where sal=(
SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal));

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / jaishree singh

select emp_name,salary from
(select emp_name,salary, row_number() over (order by salary)
rownumber from employee) E
where E.rownumber = 3

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / neeraj kumar

select top(1) Salary
from(select distinct top(n) Salary
from emp
order by Salary desc ) a
order by Salary




Note-you can find out any position salary through top(n).
n=1,2,3,4,5,6,7,8,9..................

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / eldho k scaria

There are two methods:(Suppose table name is EMPLOYEE,
Colomn name is SALARY, and N=6)

SELECT * FROM EMPLOYEE
WHERE SALARY IN
(SELECT TO 1 SALARY (SELECT DISTINCT TOP 6 SALARY FROM
EMPLOYEE ORDER BY SALARY DESC)
A ORDER BY SALARY)
or
SELECT * FROM EMPLOYEE E1
WHERE (6-1)=(SELECT COUNT (DISTINCT (E2.SALARY))
FROM EMPLOYEE E2
WHERE E2.SALARY>E1.SALARY)

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / anija

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC)
ORDER BY salary

Is This Answer Correct ?    1 Yes 0 No

how to find nth highest salary..

Answer / elumalai.k

select salary from tablename t1
where n=(select count(*)from tablename t2
where t1.salary<=t2.salary)

Is This Answer Correct ?    16 Yes 16 No

Post New Answer

More SQL Server Interview Questions

If i am handling 150 servers then how to check the active jobs of all the servers?

0 Answers  


How to get @@error and @@rowcount at the same time?

0 Answers  


How to attach adventureworkslt physical files to the server?

0 Answers  


What is a periodical index?

0 Answers  


How can I get data from a database on another server?

0 Answers  


What are pages and extents? : SQL Server Architecture

0 Answers  


Differences between Standby Vs No recovery?

2 Answers   Wipro,


How can I create a new template for import ? : sql server management studio

0 Answers  


How to get number of days in a given year?

4 Answers   ADP,


how to take backup bcp out for a column in table in sql server?

0 Answers  


While you are inserting values into a table with the insert into .. Values option, does the order of the columns in the insert statement have to be the same as the order of the columns in the table?

0 Answers  


How can we improve performance by using SQL Server profiler?

0 Answers   QuestPond,


Categories