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

Answers were Sorted based on User's Feedback



How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / s n yagneswara babu

TO FIND THE SECOND HIGHEST SAL IN EMP TABLE

select max(sal) from emp where sal not in(select max(sal)
from emp)

TO FIND THE 3RD HIGHEST SAL IN EMP TABLE

select max(sal) from emp where sal not in(select distinct
top 2 sal from emp order by sal desc)

TO FIND THE Nth HIGHEST SAL IN EMP TABLE

select max(sal) from emp where sal not in(select distinct
top N-1 sal from emp order by sal desc)

yagneswara babu
yagnesh_sn@yahoo.co.in

Is This Answer Correct ?    39 Yes 6 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / saikrishna reddy .k

To find second highest salary
select max(sal) from emp where sal not in (select max(sal)
from emp)

to find order
select top 5 8 from emp order by sal desc

Is This Answer Correct ?    30 Yes 17 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / punit kumar

1.To find second highest salary

select max(sal) from emp_record
where sal not in (select max(sal)from emp_record)


2.To find second highest salary

select max(sal) from emp_record
where sal < (select max(sal)from emp_record)


3.create table punit(rn varchar(30),salary int)
insert into punit values('a',10000)
insert into punit values('b',12000)
insert into punit values('c',15000)
insert into punit values('e',25000)
insert into punit values('d',22000)
insert into punit values('f',30000)
insert into punit values('h',35000)
insert into punit values('g',32000)
insert into punit values('i',32000)
select * from punit order by salary desc
Select * from punit a where 1=(select count(distinct b.salary)
from punit b where a.salary <=b.salary)
Select * from punit a where 2=(select count(distinct b.salary)
from punit b where a.salary <=b.salary)
Select * from punit a where 3=(select count(distinct b.salary)
from punit b where a.salary <=b.salary)
Select * from punit a where 4=(select count(distinct b.salary)
from punit b where a.salary <=b.salary)



by:-

PUNIT CHAUHAN

DELHI
MCA STUDENT STUDIS IN NOIDA

Is This Answer Correct ?    9 Yes 0 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / neon

select salary from emp
where salary = (select max(salary) from emp
where salary <>(select max(salary) from emp)

Is This Answer Correct ?    8 Yes 3 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / subhranghshu bhattacharjee

first find second largest salary in the emp database:

select min(sal)sal from(select sal from emp order by sal
desc)
where rownum<3
u can find 3rd,4th... so on ,only change rownum
like rownum<4,rownum<5 ... so on

Is This Answer Correct ?    10 Yes 8 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / amar banerjee

sol1> select MAX(salary) from emp where salary< (select MAX(salary) from emp);

sol2> select salary from emp sort by salary desc limit 1,1;

for finding nth position

select salary from emp sort by salary desc limit n-1,1;

Is This Answer Correct ?    4 Yes 2 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / pankaj arya

select top 1 sal from emp where empid in(select top 2 empid
from emp order by sal desc) order by
sal asc

if you want to get 3rd one than put 'top 3' in subquery and
same for 4th, 5th....

Is This Answer Correct ?    15 Yes 14 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / prafulla borade

SELECT MAX(VCRG_ID) FROM dbo.TRN_VEHICLE_CARGO WHERE VCRG_ID< (SELECT MAX (VCRG_ID) FROM dbo.TRN_VEHICLE_CARGO)

Is This Answer Correct ?    3 Yes 2 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / prathapshankarshiva

select max(salary) from (select salary from table1 where
salary<(select max(salary) from table1))

Is This Answer Correct ?    1 Yes 0 No

How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ....

Answer / 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

More SQL Server Interview Questions

What are tables in sql server?

0 Answers  


In my application I have a process which picks the scanned files (tif format) from a shared location and it links to application and shown on it.The actuall issue is that my process picks the file before it is completly written or scanned which results in displaying few parts of the image or incomplete image.I need to check if the file is not completly scanned or written then do not link it to application.Please help if any body tell me that how can i check that file is in written phase or locked through DTS.thanking you in advance

0 Answers  


write an SQL query to list the employees who joined in the month of January?

0 Answers   Agilent, Amdocs,


What is the recovery model?

0 Answers  


What is Dedicated Administrator Connection in sql server 2005?

2 Answers  






What is primary key and example?

0 Answers  


How to connect of datebase with sql express.?

0 Answers   MCN Solutions,


Mention a few common trace flags used with sql server?

0 Answers  


What is the difference between update lock and exclusive lock?

0 Answers  


What is the use of stored procedure?

0 Answers  


Does a specific recovery model need to be used for a replicated database? : sql server replication

0 Answers  


what is the difference between delete table and truncate table commands? : Sql server database administration

0 Answers  


Categories