Write a query to get 2nd maximum salary in an employee table ?
Answers were Sorted based on User's Feedback
Answer / sandeep
select top(1) a.salary
from
(
select top(2)sal
from
employee
order by salary desc
)a
order by a.salary asc
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mark berlin.
REM solution #1:
select * from(
select distinct nvl(salary,-1) as sal
from employees
where nvl(salary,-1) < (select max(nvl(salary,-1)) from
employees)
order by nvl(salary,-1) desc)
where rownum=1;
REM Solution #2
select * from (
select distinct salary from employees
order by salary
desc
)
where rownum < 3
minus
select * from (
select distinct salary from employees
order by salary
desc
)
where rownum =1;
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sushant hole
select max(salary) from employees where salary<(select max(salary) from
employees);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / boby
select max(MAXI) from
(SELECT max(slno) AS MAXI FROM EMPLOYEE WHERE slno not IN(SELECT max(slno) FROM EMPLOYEE )
GROUP BY slno)a
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / neha singh
select min(sal)
from
(select sal from
(select sal from emp
order by sal desc)
where rownum<=2)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / baburav zore
select max(sal) from employee where sal<(select sal from employee);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / akshay
Select ename, eno, sal, rownum
from (select ename, eno, sal from emp order by sal desc)
where rownum = 2;
| Is This Answer Correct ? | 7 Yes | 7 No |
Answer / ahmad
Select Max(VacationHours) "MVacHrs"
from HumanResourcesEmployee
where VacationHours not in (Select Max(VacationHours)
from HumanResourcesEmployee)
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / google
Select min(sal) from emp where sal in (
select top 3 sal from emp
order by sal desc )
| Is This Answer Correct ? | 0 Yes | 0 No |
How do you modify a trigger?
How many sql statements are used?
can i write pl/sql code in a package
Hi Everyone, How to get fist and last record from a table in oracle? Thanks in advance
How to install oracle sql developer?
How can you create an empty table from an existing table?
what is the difference between the query and corelated query
8 Answers HSBC, IBM, TCS, Xenosoft,
What does <> sql mean?
Fetch an entire row from the employees table for a specific employee ID:
What are sql functions? Describe in brief different types of sql functions?
List out the acid properties and explain?
Can %notfound return null after a fetch?
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)