Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

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..

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

 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..

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

 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..

select top 1 * from (select top 2 * from emp order by sal
desc ) a order by sal asc

Plz try this.

 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..

hai..

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

->here,the sub inner query finds the max sal from emp table.
->the main inner query find out the max sal that is less
than the sub inner query max sal.
->the sub query result is sent to outer query..

 Is This Answer Correct ? 2 Yes 1 No

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

hi,
my id is ravi106109@gmail.com

select sal from emp a
where 1=(select count(b.sal) from emp b
where a.sal<b.sal) order by sal desc;

and also dileep is write

 Is This Answer Correct ? 3 Yes 3 No

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

we have to use distinct key word there is a possibility
that two person having same salary.

select top 1 sry from (select distinct top 2 sry from emp
order by sry desc)t1 order by sry asc

 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..

This query is generalised query if u replace 2 by 100 ,
then you will get 100th max salary

select top 1 salary from employee where salary in( select
top 2 salary from employee order by salary desc) order by
salary asc

 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..

To find Top 3 max Sal.... to put any number on the place of
3 to find nth max sal...

select top 3 sal from emp order by sal desc

 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..

select e.* from
(select row_number() over (order by salary desc) as Rno,*
from employee)e
where e.Rno = 2

 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..

Select max(sal) from emp
where id='1233' and Sal< (select max(sal) from emp)

 Is This Answer Correct ? 1 Yes 1 No

More SQL Server Interview Questions

what is bit datatype and what's the information that can be stored inside a bit column? : Sql server database administration

What are the advantages of using a stored procedure?

Tell me can we use custom code in ssrs?

how to restart sql server in single user mode? How to start sql server in minimal configuration mode? : Sql server database administration

SYNTAX FOR VIEWS WITH EXAMPLE HOW TO LINK TWO TABLES

What is the difference between the 2 operating modes of database mirroring?

How to delete duplicate rows in sql server?

How send email from database?.

List the different index configurations possible for a table?

How to encrypt Strored Procedure in SQL SERVER?

What are the properties of sub-query?

What are key constraints?

Categories