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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Create a dts package to produce a text file using the ‘update statistics’ command for the tables in a database with obsolete statistics.

703


explain the difference between oracle- sql and sql server sql ? if both are same y we r using 2 sw.s?

2188


What are the differences between triggers and stored procedures?

726


Why transaction is important?

721


What is service broker?

765






What happens if date-only values are provided as date and time literals?

750


Explain the concepts and capabilities of sql server?

689


How to round a numeric value to a specific precision?

768


How do we Backup SQL Azure Data?

98


Do you know what are pages and extents? : SQL Server Architecture

737


What is named query? : sql server analysis services, ssas

691


Explain different backup plans?

702


Do you know the cursor optimization tips?

744


What is normalization and what are the advantages of it?

706


Explain the concept of recursive stored procedure.

664