how to get second highest salary in SQL(as/4000

Answers were Sorted based on User's Feedback



how to get second highest salary in SQL(as/4000..

Answer / premchand

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

Is This Answer Correct ?    34 Yes 12 No

how to get second highest salary in SQL(as/4000..

Answer / satheeshkumar

Select max(sal) From Employee where sal not in ( Select max
(sal) From Employee)

Is This Answer Correct ?    24 Yes 4 No

how to get second highest salary in SQL(as/4000..

Answer / sachin

select max(sal) from employees
where salary < (select max(sal) from employees);

Is This Answer Correct ?    19 Yes 3 No

how to get second highest salary in SQL(as/4000..

Answer / karunakarreddy.boyapally

SELECT DISTINCT A.SAL FROM EMP A
WHERE &N=(SELECT COUNT(DISTINCT(B.SAL)) FROM EMP B
WHERE A.SAL<B.SAL)

IF SUPPOSE IF U WANT 1 HIGEST SALARY GIVE N=1
IF SUPPOSE IF U WANT 2 HIGEST SALARY GIVE N=2
IF SUPPOSE IF U WANT 3 HIGEST SALARY GIVE N=3

Is This Answer Correct ?    10 Yes 1 No

how to get second highest salary in SQL(as/4000..

Answer / deepak

select max(sal) from emp where sal!=(select max(sal) from emp);

Is This Answer Correct ?    12 Yes 5 No

how to get second highest salary in SQL(as/4000..

Answer / raji_4u

select *
from emp e1
where 2 = ( select count(distinct sal)
from emp e2
where e1.sal <= e2.sal
)

Is This Answer Correct ?    8 Yes 1 No

how to get second highest salary in SQL(as/4000..

Answer / selvaraj v , anna univ coe

SELECT * FROM Employee e
WHERE 2=(SELECT COUNT(DISTINCT Salary) FROM Employee x
WHERE x.Salary >= e.Salary);

Is This Answer Correct ?    4 Yes 0 No

how to get second highest salary in SQL(as/4000..

Answer / sreekanth

SELECT MIN(SAL)
FROM(SELECT DISTINCT SAL FROM EMP
ORDER BY SAL DESC)
WHERE ROWNUM <= :N
where n is the nth highest salary.
In most of the answers,our friends have written 'where
rownum=2',but this never retreives a row.

Is This Answer Correct ?    5 Yes 2 No

how to get second highest salary in SQL(as/4000..

Answer / c srirammulu

select * from emp a where &n=(select count(distinct (sal))
from emp f where a.sal<f.sal)

Is This Answer Correct ?    4 Yes 1 No

how to get second highest salary in SQL(as/4000..

Answer / devi

select sal from (select sal,rank() over(order by sal desc)
as rank from emp) where rank>1 and rank<3

Is This Answer Correct ?    4 Yes 1 No

Post New Answer

More SQL PLSQL Interview Questions

What is the difference between anonymous block and named blocks?

3 Answers  


which operator is used in query for pattern matching? : Sql dba

0 Answers  


What are predefined functions in sql?

0 Answers  


Hi All, I am new to both this blog and technology. I was able to see a response for one of the questions on triggers as below. I would like to know why are we using " if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then" instead, can't we use " if sysdate = 'sunday' then". I can understand the use of "rtrim", but dont know y v r using to_char. I have seen this in many cases but did not get a convincible explaination. Please help me with this and do excuse if this question sounds silly. Thanks in advance...... create or replace trigger trg_sun before insert on <table name> begin if rtrim(to_char(sysdate,'day'))=rtrim('sunday') then raise_application_error(-20345,'no transaction in sunday'); end if; end trg_sun;

2 Answers  


What is a full join?

0 Answers  






What is Temp Table and type of temp table?

1 Answers   HP, SLK,


List the different type of joins?

0 Answers  


Can we use loop in sql?

0 Answers  


What is record type in pl sql?

0 Answers  


explain what is mysql? : Sql dba

0 Answers  


What is pl/sql language case sensitive?

0 Answers  


explain about mysql and its features. : Sql dba

0 Answers  


Categories