Write a query to find second highest salary of an employee.
Answers were Sorted based on User's Feedback
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 |
Answer / cooldude
select max(sal) from Emp where sal < (select max(sal) from
Emp)
| Is This Answer Correct ? | 14 Yes | 2 No |
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 |
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 |
Answer / monika
select max(sal) from emp where sal<select max(sal) from emp
| Is This Answer Correct ? | 8 Yes | 6 No |
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 |
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 |
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 |
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 |
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 |
i have table T!. A B C D NULL 1 2 3 4 NULL 5 6 7 8 NULL 9 10 11 12 NULL. I WANT COUNT OF NULL VALUES IN TABLE. WRITE A QUERY.
What is mdf ldf and ndf?
what is the difference between union and union all
14 Answers IBM, Luxoft, Oracle,
What do you understand by pl/sql cursors?
What does pl sql developer do?
what is query cache in mysql? : Sql dba
What is the need of a partition key?
I have one table and column is c1 pk, c2 not null,c3 not null and 200 row in it and i add c4 column and value, how can is possible
How to convert comma separated string to array in pl/sql?
What are tables in sql?
Explain the advantages and disadvantages of stored procedure?
What are the attributes of SQL*PLUS ?
2 Answers Dream Careers, Oracle,
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)