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

What is the difference between a query and a report?

680


How do you declare a user-defined exception?

718


What is trigger price?

731


What is the unique index?

726


How do you update a value in sql?

717






Is it possible for a table to have more than one foreign key?

774


Can we call dml statement in function?

765


What is oracle and pl sql?

835


How do I write a cron which will run a sql query and mail the results to agroup?

717


Does mysql_real_escape_string prevent sql injection?

693


How to know the last executed procedure?

809


what are different types of collation sensitivity? : Sql dba

757


what are the advantages and disadvantages of views in a database? : Sql dba

765


Why plvtab is considered as the easiest way to access the pl/sql table?

835


Is natural join same as inner join?

683