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

what are the advantages of using stored procedures? : Sql dba

0 Answers  


How many types of triggers exist in pl/sql?

0 Answers  


1 SELECT a.field1, b.field2, c.field3, d.field4 2 FROM atable a, atable b, ctable c, dtable d 3 ? 4 ORDER BY 1 What is the minimum number of joins that must be specified on line 3 in the sample code above to properly link the tables? Notice that the table "atable" is aliased twice: once as "a" and once as "b." 1. One join 2. Two joins 3. Three joins 4. Four joins 5. Five joins

6 Answers   Sonata,


What is string join?

0 Answers  


What is primary key and unique key?

0 Answers  






How do you use join?

0 Answers  


Does a primary key have to be a number?

0 Answers  


how many sql ddl commands are supported by 'mysql'? : Sql dba

0 Answers  


Enlist the data types that can be used in pl/sql?

0 Answers  


What is the basic difference between a sql and stored procedure ?

2 Answers   L&T,


How do I view a view in sql?

0 Answers  


What are tuples in sql?

0 Answers  


Categories