can anybody tell us, how to select 2nd max salary from
table.
my id is ashish.akk@gmail.com




Answers were Sorted based on User's Feedback



can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / dileep.t

If you need the second highest salary only
then following will also work,

select Max(Salary) from TableName
where Salary not in(
Select Max(Salary) from TableName)

Is This Answer Correct ?    18 Yes 3 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / preeti chauhan

CREATE TABLE T1(SALARY int, [NAME] varchar(50))
SELECT TOP 1 SALARY FROM (SELECT TOP 2 SALARY FROM T1 ORDER
BY SALARY DESC)T1 ORDER BY SALARY

Is This Answer Correct ?    15 Yes 3 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / kumar_kisna

select max(salary) from table where salary<(select max
(salary) from table)

Is This Answer Correct ?    4 Yes 1 No




can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / divya

select max(sal) from tablename where sal<(select
max(sal)from tablename)

Is This Answer Correct ?    3 Yes 0 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / arun kumar ks

In the case more than one highest SALARY, only the Dilip’s
answer is correct.

Is This Answer Correct ?    3 Yes 1 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / sabin v jacob

SELECT Min(Sal) FROM (SELECT TOP 2 Sal FROM emp ORDER BY
Sal desc) as Temp

or

SELECT Min(Sal) FROM emp WHERE Sal IN(SELECT TOP 2 Sal FROM
emp ORDER BY Sal DESC)

Is This Answer Correct ?    5 Yes 3 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / rajendra

Select Top 1 * From Tablename where salary in
(select top 2 salary from tablename order by salary desc)
order by salary asc

Is This Answer Correct ?    2 Yes 0 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / neeru

I think Daleep answer is not so precise, if you want 3rd or
ny specified answer, this only can only be seems right for
2nd highest salary, else, its not optimise query.I found
Preeti's query more optimistic and accurate.

Is This Answer Correct ?    1 Yes 0 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / selvaraj.v

In SQL Server 2000 Query:
-------------------------

select max(salary) from Employee where salary not in(select
max(salary) from employee)

This Query only selects the 2'nd Higehest Salary in that
table. So, you will try...

Is This Answer Correct ?    1 Yes 0 No

can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com..

Answer / harikumar

select max(salary) as secondMax from employee where id <>
(select max(salary) from employee)

Is This Answer Correct ?    1 Yes 0 No

Post New Answer



More SQL Server Interview Questions

In which format does an image save in SQL Server database ?

0 Answers   MCN Solutions,


How would you add a section to a table?

0 Answers  


Explain the third normal form(3nf)?

0 Answers  


Distinguish between commit and rollback?

0 Answers  


What is the template in sql?

0 Answers  






What is service broker?

0 Answers  


default databases available in sql server and there uses ?

4 Answers   TCS,


How to find the second highest salary of an employee?

0 Answers  


Can I know,how to Execute Funcion and Trigger through command(Manualy Execution) in MS SQL/SERVER 2005,give me answer with Example.

1 Answers  


Define left outer join?

0 Answers  


Explain sql server authentication modes?

0 Answers  


what is an sql server?

1 Answers  






Categories