how to find the second highest salary from emp table?
Answer Posted / amit singh
forget the book
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 on this site)
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
what is row? : Sql dba
What is sql*plus?
Why do we use view in sql?
How can get second highest salary in sql?
how to shutdown mysql server? : Sql dba
What is trigger in sql?
What is trigger in pl sql with examples?
When sql appeared?
What is a nested table in word?
What is the difference between nvl function, ifnull function, and isnull function?
What is data control language (dcl)?
how many ways we can we find the current date using mysql? : Sql dba
how to calculate the difference between two dates? : Sql dba
What is sql catalog?
What is difference between table and view?