Write a query to find second highest salary of an employee.

Answers were Sorted based on User's Feedback



Write a query to find second highest salary of an employee. ..

Answer / gautam poonia

SELECT sal
FROM (SELECT sal FROM emp
ORDER BY sal desc)
WHERE RowNum<=2
minus
SELECT sal
FROM (SELECT sal FROM emp
ORDER BY sal desc)
WHERE RowNum<=1

Is This Answer Correct ?    17 Yes 1 No

Write a query to find second highest salary of an employee. ..

Answer / cooldude

select max(sal) from Emp where sal < (select max(sal) from
Emp)

Is This Answer Correct ?    14 Yes 2 No

Write a query to find second highest salary of an employee. ..

Answer / gvmahesh

I write the query for this question using OLAP functions.

select e1.* from (select ename,sal,rank()
over(order by sal desc) rank from emp) e1
where e1.rank=2;

Is This Answer Correct ?    5 Yes 1 No

Write a query to find second highest salary of an employee. ..

Answer / sathish p

select e1.* from (select ename,sal,rank()
over(order by sal) rank from emp) e1
where e1.rank=2;

Is This Answer Correct ?    3 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / monika

select max(sal) from emp where sal<select max(sal) from emp

Is This Answer Correct ?    8 Yes 6 No

Write a query to find second highest salary of an employee. ..

Answer / mubin ahmad

select salary from employee e1 where 2=(select count(*)
from employee e2 where e2.salary>=e1.salary)

Is This Answer Correct ?    2 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / humayun quaiser

slect max(sal) from emp
where sal not in (select max(sal) from emp);

or

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

or

select distinct sal from emp e
where 1=(select count(distinct sal) from emp
where sal>e.sal);

Is This Answer Correct ?    2 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / versaites

select top 1 emp_total_sal,emp_name from (
select top 2 emp_total_sal,emp_name from employee_table
ORDER BY emp_total_sal DESC) a
ORDER BY emp_total_sal ASC

Is This Answer Correct ?    4 Yes 3 No

Write a query to find second highest salary of an employee. ..

Answer / manoranjan

to select the nth highest salary from emp table

select distinct(a.sal) from emp a where &n=
(select count(distinct(b.sal))from emp b where a.sal<=b.sal);

Is This Answer Correct ?    3 Yes 2 No

Write a query to find second highest salary of an employee. ..

Answer / senorita

select ename,salary from (select rownum,ename,salary from
emp
order by desc) where rownum=2;

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More SQL PLSQL Interview Questions

i have a table with fields(id,name,accnt_type)and in account type are FD,SAVING,RD. Write a query to get How many number of People are in each type of Account?

6 Answers   Fidelity, IBM,


How do I access sql anywhere database?

0 Answers  


HP Interview -2016 Unix 1) grep command in unix 2) what is set command

1 Answers   HCL,


What are reports usually used for?

0 Answers  


Can you have more than one key in a database?

0 Answers  






What are the different types of triggers?

0 Answers  


what are Dynamic SQL statements?

9 Answers  


how to eliminate null values in a column i.e table vlaues 1 2 3 NULL 3 4 1 5 NULL i want output like this 1 2 3 3 4 1 5 i dnt want to use nvl is null and i dnt want replace the NULL value with any value i.e nvl(col,o);

11 Answers   Satyam,


Will truncate release space?

0 Answers  


I want to execute a piece of code before calling a procedure. How to achieve it?

1 Answers   Oracle,


When you have to use a default "rollback to" savepoint of plvlog?

0 Answers  


How to remove duplicate rows from a table?.

3 Answers  


Categories