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 trigger price?

538


How do I view output in sql developer?

574


How do you add a column to a table?

598


Can we delete column in sql?

559


What is the use of index in sql?

553






Define overloaded procedure?

620


Why do we use subquery?

487


What action do you have to perform before retrieving data from the next result set of a stored procedure ?

2091


What are the possible values for the boolean data field?

519


what is sub-query? : Transact sql

596


What is sql data?

546


Can I learn sql in a week?

547


Mention what is the use of function "module procedure" in pl/sql?

561


What is recursive stored procedure?

598


Can a foreign key be a duplicate?

499