Find out the 3rd highest salary?

Answer Posted / amit singh

Empsal table data
700
500
100
900
400
200
600
750


query to find second highest salary from table Empsal

mysql>select distinct(max(e.salary)) from Empsal e
>where e.salary in(
>select e1.salary from Empsal e1 where e1.salary<
(select max(salary) from Empsal));

Output=750



query to find third highest salary from table Empsal


mysql>select distinct(max(e.salary)) from Empsal e
>where e.salary in(
>select e1.salary from Empsal e1 where e1.salary<
>(select max(e1.salary) from Empsal e1
>where e1.salary IN(
>select e2.salary from Empsal e2 where
>e2.salary<(select max(salary) from Empsal))));
Output=700

RUN THE QUERY THEN ARG
amitsing2008@gmail.com(amit is back)

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to use regular expression in pattern match conditions? : Sql dba

532


Which one is faster ienumerable or iqueryable?

491


explain advantages of innodb over myisam. : Sql dba

652


What is meant by cursor in sql?

551


What is scalar data type in pl sql?

565






What is application trigger?

548


What is difference between sql and oracle?

570


Is not equal in sql?

573


What are the two types of exceptions in pl/sql?

550


What is blind sql injection?

580


What is primary key secondary key alternate key candidate key?

548


What sql does db2 use?

549


What is an index in sql with example?

521


what is the difference between a web-garden and a web-farm? : Sql dba

565


How many types of cursors are available in pl/sql?

588