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 is a covering index?
What is an index in sql?
When is update_statistics command used?
List the different index configurations possible for a table?
Explain having clause and where clause?
Can you name a few encryption mechanisms in sql server?
What are different types of replication in sql server?
What do you understand by recursive stored procedure?
What is difference between after and before?
Can you move the resources after pausing the node? : sql server database administration
Write a program using SQL queries to find a unique entry in a table.
Do you know what is rank function?
what information is maintained within the msdb database? : Sql server administration
How to check parameter value in stored procedure sql server?
How do I find the sql server version?