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 / rajasekhar.v

For selecting Nth highest salary...

SQL> select rownum rank,ename,sal from
(select ename,sal from emp order by sal desc)
group by rownum,ename,sal
having rownum = &n;
'n' may be any valid number required..

Is This Answer Correct ?    1 Yes 0 No

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

Answer / murali

SELECT
MAX(Sal)
FROM
Emp
WHERE
Level=&Levelno
ORDER BY PRIOR Sal>Sal
GROUP BY Level

--Here we have to give &Levelno = 2

Is This Answer Correct ?    1 Yes 0 No

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

Answer / dilip

select rank,sal from(select rownum rank,distinct(sal) from
emp order by sal desc)
where rank=2;

Is This Answer Correct ?    1 Yes 0 No

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

Answer / shahid parvez

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

Is This Answer Correct ?    1 Yes 1 No

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

Answer / gyana ranjan behera

select ename,sal.rn from(select ename,sal,rownum rn from(select ename,sal from emp order by sal desc))where rn=2;

Is This Answer Correct ?    0 Yes 0 No

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

Answer / satheesh

SELECT MAX(SAL) FROM EMP A
WHERE SAL NOT IN(SELECT MAX(SAL) FROM EMP B);

Is This Answer Correct ?    0 Yes 0 No

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

Answer / manikumar

Select Sal from Emp where Sal in (Select Max(Sal) from Emp)

Is This Answer Correct ?    0 Yes 1 No

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

Answer / oboyah

SELECT e1.* from ( SELECT last_name, salary,
DENSE_RANK() OVER ( ORDER BY salary DESC) rank
FROM employees) e1 where e1.Rank = 2;

Is This Answer Correct ?    0 Yes 1 No

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

Answer / om patel

select (distinct(a.sal) from emp e where rownum=&N(select
count(distinct(b.sal)) from emp b where a.sal<=b.sal)

Is This Answer Correct ?    0 Yes 1 No

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

Answer / akilis.org@hotmail.com

Let us assume that
Table Name:salary
Coloumn Name:maxsal(int)
select * from salary order by maxsal desc limit 1,1;

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL PLSQL Interview Questions

Which one of the following is a reason that an INSERT statement might cause an error instead of executing correctly? 1. The INSERT statement was attempting to insert a record into a view that was created from more than one table. 2. The INSERT statement was attempting to insert a record using a combination of constants and values from an existing table. 3. The INSERT statement was attempting to insert a record with a non-NULL value into a table that has that column defined as NULL. 4. The INSERT statement was attempting to insert a record into a table by selecting a record from that same table. 5. The INSERT statement was attempting to insert a record into a view rather than a table.

1 Answers   Sonata,


how to create a primary key with out creating an index?

9 Answers   TCS,


How do I find duplicates in sql?

0 Answers  


How to create a view on a table which does not exists

4 Answers   Oracle, TCS,


Why is theta join required?

0 Answers  






how to drop an existing view in mysql? : Sql dba

0 Answers  


define sql insert statement ? : Sql dba

0 Answers  


Question: Below is the table city gender name delhi male a delhi female b mumbai male c mumbai female d delhi male e I want the o/p as follows: male female delhi 2 1 mumbai 1 1 Please help me in writing the query that can yield the o/p mentioned above?

2 Answers  


What is trigger and stored procedure in sql?

0 Answers  


What is varchar data type in sql?

0 Answers  


What is update query?

0 Answers  


what is rdbms? : Sql dba

0 Answers  


Categories