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
What are data files?
How many types of local tables are there in sql server?
How retrieve field names from the table in SQL through JAVA code?
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?
Do you know what is fill factor and pad index?
Explain the phases a transaction has to undergo?
How does stuff differ from the replace function?
What is Sqlpaging in SqlServer 2005 ?
How to get the definition of a stored procedure back?
How many columns can we include on clustered index ?
Tell me can we use custom code in ssrs?
what is the Ticketing tool used in Wipro technologies at Bangalore...???
When I delete any data from a table, does the sql server reduce the size of that table?
Explain “not null constraint” in sql server?
How to use column default values in insert statements in ms sql server?