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
explain different levels of normalization? : Sql server database administration
Can we delete data from a view?
Where is my database stored on the hard disk in ms sql server?
How to connect php with different port numbers?
What is the user of Primary key?
Explain go command in sql server?
can you instantiate a com object by using t-sql? : Sql server database administration
Explain data warehousing in sql server?
Difference between Inner vs outer joins?
what is the difference between Delete and Truncate command in SQL
Why truncate is ddl command?
Explain try...catch with sql server?
How to enter unicode character string literals in ms sql server?
What is the sql case statement used for?
Explain primary key, foreign key and unique key?