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
Can I delete event logs?
Do you know what is similarity and difference between truncate and delete in sql?
If the job running very slow what is the action you do
What is the difference between SQL notification and SQL invalidation?
What is filtered index?
What is molap and its advantage? : sql server analysis services, ssas
Which language is supported by sql server?
You are designing a strategy for synchronizing an SQL Azure database and multiple remote Microsoft SQL Server 2008 databases. The SQL Azure database contains many tables that have circular foreign key relationships?
How to use "begin ... End" statement structures in ms sql server?
List out the differences between the clustered index and non-clustered index in sql server?
How to test odbc dsn connection settings?
What is sql profiler. What are the default templates with it? : sql server database administration
We need to perform what steps in the following order to work with a cursor?
How to create hyperlink from returned sql query ?
Write a query for primary key constraint with identity key word?