How to find out the 10th highest salary in SQL query?

Showing Answers 1 - 25 of 25 Answers

Raks

  • Jun 27th, 2006
 

--Here the query to find out 10th Max salary

Table - Tbl_Test_Salary 
Column - int_salary

select max(int_salary) 
     from Tbl_Test_Salary 
            where int_salary in
               (select top 10 int_Salary from Tbl_Test_Salary order by int_salary)

  Was this answer useful?  Yes

Naresh Challagulla

  • Jun 29th, 2006
 

Actually it should be:

select min(int_salary) from Tbl_Test_Salary 
      where int_salary
in
               (
select top 10 int_Salary from Tbl_Test_Salary order by int_salary desc)

 

  Was this answer useful?  Yes

Karthick Gunasekaran

  • Jul 11th, 2006
 

Both the given answers might not suit if the table contains same salary for more than one person. In this case, we juz need to add DISTINCT when pulling the values - select min(salary) from (select distinct top 10 salary from employee order by salary desc) t1

  Was this answer useful?  Yes

jeya

  • Jul 18th, 2006
 

Hi ,

As per your advice i used the above query to retrieve the top 10 values from a table in sybase.But unfortunately its throwing error "Incorrect syntax near the keyword 'top' ".Kindly let me know what is the problem with the below query.

Query:

select * from MKP_MKT_PRICE b where b.MKP_SEC_ID in (
select top 10 a.MKP_SEC_ID from MKP_MKT_PRICE a
where a.MKP_PRICE_DT='Jul 18 2006' order by a.MKP_MKT_PRC desc)

  Was this answer useful?  Yes

Raj

  • Jul 25th, 2006
 

Hi,

select max(allowedamount)
     from tbl_InsuranceProceduresAmt
            where allowedamount in
               (select top 10 allowedamount from tbl_InsuranceProceduresAmt order by allowedamount desc)

This is perfect result

  Was this answer useful?  Yes

saxenaamit_mca

  • Jul 25th, 2006
 

Find out nth highest salary from emp table
 SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);

Enter value for n: 2
      SAL
---------
     3700

  Was this answer useful?  Yes

Gautam Kumar

  • Jul 27th, 2006
 

TO find nth Salary

select min(sal) from (select distinct sal from emp order by sal desc) where rownum<=&n

  Was this answer useful?  Yes

gautamsinha01

  • Jul 27th, 2006
 

select min(sal) from (select distinct sal from emp order by sal desc) where rownum<=&n

  Was this answer useful?  Yes

hani

  • Aug 15th, 2006
 

hi,

the solution is :

SELECT TOP10 salary_field FROM employees_table ORDER BY salary_field DESC

nth salary

select salary

from table_name a

where &n=(select count(salary) from table_name b where a.salary<=b.salary);

n salaries

select salary

from table_name a

where &n>=(select count(salary) from table_name b where a.salary<=b.salary);

Ram Pratap Singh

  • Sep 9th, 2006
 

select * from emp
where sal =  ( select sal from (select rownum rnum, sal
                                    from(select distinct sal from emp
                                           order by sal desc
                                         )
                                  )
                   where rnum = &salnum
             )

&salnum :  what position's sal

like 3,12,5,10

Raju.S

  • Oct 3rd, 2007
 

1) Select * from ( select salary,DENSE_RANK() over(order by salary desc)
toprank from employee) where toprank=n


2) select * from employee a WHERE (n-1)= ( select count(*) from employee b
WHERE b.salary > a.salary )


Both the Queries are giving result for to find the 10 highest salary in SQL
query in the above queries n=10 for to find 10th highest salary.

  Was this answer useful?  Yes

PARDHA SARADHY NVS

  • Oct 12th, 2007
 

Using TOP is possible only with MS SQL Server. This keywork TOP is not availbale in Oracle.

  Was this answer useful?  Yes

In Teradata, even if the duplicate salaries are present, below query can be used.

sel b.* from 
(
sel a.*,rank() over (order by a.salary desc) as rnk from
(sel salary  from samples.emp
group by salary ) as a
) b
where b.rnk=10

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions