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
How does sql profiler work?
Can we insert in view in sql?
What are data types in pl sql?
What are the main features of cursor?
How to prepare for oracle pl sql certification?
what is a composite primary key ? : Sql dba
Is sql between inclusive?
What is the best free sql database?
What is a constraint? Tell me about its various levels.
Can we join two tables without common column?
What is a primary key sql?
What is the order of sql select?
What is a unique constraint?
Can we connect to postgresql using sql developer?
How do I save the results of sql query in a file?