How to find the second largest salary in the emp database and
also How to find 3rd,4th and so on ........ in the emp database

plz mail the answer @ mak2786@gmail.com

Answer Posted / narendra soni

create table #a(rn varchar(30),salary int)
insert into #a values('a',10000)
insert into #a values('b',12000)
insert into #a values('c',15000)
insert into #a values('e',25000)
insert into #a values('d',22000)
insert into #a values('f',30000)
insert into #a values('h',35000)
insert into #a values('g',32000)
insert into #a values('i',32000)
select * from #a order by salary desc
Select * from #a a where 1=(select count(distinct b.salary)
from #a b where a.salary <=b.salary)
Select * from #a a where 2=(select count(distinct b.salary)
from #a b where a.salary <=b.salary)
Select * from #a a where 3=(select count(distinct b.salary)
from #a b where a.salary <=b.salary)
Select * from #a a where 4=(select count(distinct b.salary)
from #a b where a.salary <=b.salary)

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to achieve Paging of records in SQL SERVER?

585


Does view occupy space?

502


What is database replication?

568


What are number line correlation administrators will use while working with a subquery?

617


What is the difference between varchar and nvarchar datatypes?

564






What are commit and rollback in sql?

558


What is subreport?

96


List the different normalization forms?

529


Beginning with sql server version 7 0, a new enhanced data type nchar was added what type of data is supported with this data type?

507


It is important form e to get the information from log files of applications executed by the task scheduler? Does sql studio save these log files? : sql server management studio

545


Where do you find the default Index fill factor and how to change it?

591


Explain cursor as data base object?

566


Can We Use Data-grids For Our Report In Ssrs?

147


Can we write a distributed query and get some data which is located on other server and oracle database?

751


How to rebuild all indexes on a single table?

575