how to find the second highest salary from emp table?

Answers were Sorted based on User's Feedback



how to find the second highest salary from emp table?..

Answer / naveed saleh

You can use this for getting nth highest salary from
Employee table as follows

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / anantkreshna v

select max(sal) from emp_table where sal < (select max(sal)
from emp_table);

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / mona thakur

SELECT *
FROM emp
WHERE salary < (
SELECT max( salary )
FROM emp )
ORDER BY salary DESC
LIMIT 1

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / kishor

select max(salary ) from employee
where
sal<(select max(salary)from employee)

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / vijay shegokar

select * from employee where salary=(select max(salary) from
employee where salary not in (select max(salary) from
employee));

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / vijay kintali

select e1.ename,e1.sal from emp e1 where n=(select count
(distinct e2.sal) from emp e2 where e1.sal<=e2.sal);

Note:n here is nth highest salary.......

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / arvind

select max(salary) from table_name where sal<(select
max(salary) from table_name)

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / bharat puri

select top 2 (salary) from emp
order by salary desc

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / gurvinder

select max(sal)from emp where sal in(select sal from emp minus select max(sal) from emp);

Is This Answer Correct ?    1 Yes 0 No

how to find the second highest salary from emp table?..

Answer / sankar sasmal

select distinct sal from emp e where 2=(select count(distinct sal)from emp s where e.sal<=s.sal)

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

State the advatage and disadvantage of Cursor's?

2 Answers  


Is pl sql still used?

0 Answers  


How can we avoid duplicating records in a query?

0 Answers  


How do you optimize SQL queries ?

6 Answers   CarrizalSoft Technologies, Infosys, Oracle,


What is the difference between cluster and non-cluster index?

0 Answers  






what is the difference between cursor FETCH and FOR LOOP ?

3 Answers   CG-VAK, Tech Mahindra,


Can you have a foreign key without a primary key?

0 Answers  


function can return value ,procedure also return value through out parameter then what is the difference?

3 Answers   3i Infotech,


Can a procedure in a package be overloaded?

0 Answers   EXL,


What is an oracle stored procedure?

0 Answers  


How many sql statements are used? Define them.

0 Answers  


Why select is used in sql?

0 Answers  


Categories