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
Why does sql studio use a single registered database repository? : sql server management studio
Difference between group by clause and having clause in SQL?
What are page splits? : SQL Server Architecture
Define cursor locking
If a table does not have a unique index, can a cursor be opened on it?
What are the restrictions while creating batches in sql server?
Explain nested trigger in sql?
role of sql sever 2005 in database rather than any other database
How extra digits are handled with numeric data type literals?
Suppose we have a table "MyTable" containing 10 rows, what query should be executed to update the odd rows "Salary" as 9000?
Explain about extended stored procedure?
How to concatenate two binary strings together?
what are questions asked in TCS for database tester (sqlserver)for 2-3 exp?
Give an example of SQL injection attack ?
What is report subscription?