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
How to achieve Paging of records in SQL SERVER?
Does view occupy space?
What is database replication?
What are number line correlation administrators will use while working with a subquery?
What is the difference between varchar and nvarchar datatypes?
What are commit and rollback in sql?
What is subreport?
List the different normalization forms?
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?
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
Where do you find the default Index fill factor and how to change it?
Explain cursor as data base object?
Can We Use Data-grids For Our Report In Ssrs?
Can we write a distributed query and get some data which is located on other server and oracle database?
How to rebuild all indexes on a single table?