How to retrieve a second highest salary from a table?
Note:Suppose salaries are in duplicate values
eg:
Name Sal
Malli 60000
Pandi 60000
Rudra 45000
Ravi 45000
Answer Posted / mallinathabj
The Following queries to retrieve the second highest salary
SQL> select max(sal) from emp where sal<(select
max(distinct(sal)) from emp);
SQL> select min(sal) from(select distinct( sal) from emp order
by sal desc) where rownum<=2;
SQL> SELECT MAX(SAL) FROM EMP WHERE SAL NOT IN (SELECT
MAX(SAL) FROM EMP);
| Is This Answer Correct ? | 13 Yes | 2 No |
Post New Answer View All Answers
what is top in tsql? : Transact sql
Write the alter statement to enable all the triggers on the t.students table.
What are different types of indexes?
What is group by in sql?
What is coalesce sql?
what is union? : Sql dba
What is trigger in sql and its types?
what is cursor. write example of it. What are the attributes of cursor.
Is not null in sql?
what is dbms? : Sql dba
How does rowid help in running a query faster?
What is database white box testing and black box testing?
What is trigger in sql?
Explain the insert into statements in sql?
how to fetch alternate records from a table? : Sql dba