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

What are data files?

771


How many types of local tables are there in sql server?

677


How retrieve field names from the table in SQL through JAVA code?

1574


You have modified 100 store procedures and want to replicate these changes from development to prodution, and production can have users using the Server/DB, how would you replicate without causing issues?

1901


Do you know what is fill factor and pad index?

745






Explain the phases a transaction has to undergo?

733


How does stuff differ from the replace function?

738


What is Sqlpaging in SqlServer 2005 ?

843


How to get the definition of a stored procedure back?

708


How many columns can we include on clustered index ?

677


Tell me can we use custom code in ssrs?

752


what is the Ticketing tool used in Wipro technologies at Bangalore...???

7809


When I delete any data from a table, does the sql server reduce the size of that table?

758


Explain “not null constraint” in sql server?

720


How to use column default values in insert statements in ms sql server?

716