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 / arun ashok

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

Is This Answer Correct ?    1 Yes 1 No

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

Answer / sandeep rana

Select top 1 salary from table where salary in(select top 2
salary from table order by salary desc)order by salary

Is This Answer Correct ?    0 Yes 0 No

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

Answer / pravin

select max(sal) from emp
where sal=(select max(sal)
from emp
where sal<(select max(sal)
from emp))

Is This Answer Correct ?    0 Yes 0 No

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

Answer / prasad237

with x as(select row_number over(order by sal desc) as rid,* from emp)
select * from x where rid=n
we can retrieve nth max sal

Is This Answer Correct ?    0 Yes 0 No

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

Answer / syaam

select a.sal from emp a
where 2=(select count(distinct b.sal) from emp b
where a.sal<= b.sal)


for getting nth max sal ..replace 2 by n


all the best

Is This Answer Correct ?    0 Yes 1 No

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

Answer / swapnl

select max(sal) from emp_det where sal not in (
select max(sal) from emp_det);

Is This Answer Correct ?    0 Yes 1 No

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

Answer / raj

Sabin's answer is perfect and simple

Is This Answer Correct ?    0 Yes 1 No

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

Answer / kumar

1 My Second Answer.

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 ?    0 Yes 4 No

Post New Answer

More SQL Server Interview Questions

How to set a database state to offline in ms sql server?

0 Answers  


You accidentally delete the msdb database what effect does this have on your existing sql databases, and how do you recover?

0 Answers  


I have all the primary data files, secondary data files as well as logs. Now, tell me can I still restore the database without having a full backup? : sql server database administration

0 Answers  


How to change the system date and time from SQL Plus Terminal ?

0 Answers   MCN Solutions,


Explain Active/Active and Active/Passive cluster configurations?

1 Answers  






plz tell me the new features of sqlserver2000,sqlserver2002,sqlserver2005

3 Answers  


About DTS usage ?

2 Answers   Cognizant, Wipro,


What is the difference between distinct clause and group by clause?

2 Answers   HHH, Value Labs,


How to create a local temporary stored procedure?

0 Answers  


how we can count records as a group of days like sum of records for(four mondays),(four tuesday)........ in a month. group the column for weekdays.

1 Answers  


What is sql profiler. What are the default templates with it? : sql server database administration

0 Answers  


What is multi-statement table-value user-defined function?

0 Answers  


Categories