Write a query to get 2nd maximum salary in an employee table ?
Answers were Sorted based on User's Feedback
Answer / priya
select rownum,empno,sal from (select
rownum,empno,sal from emp order by sal desc) group
by rownum,empno,sal having rownum=2;
This will clearly work.............
| Is This Answer Correct ? | 6 Yes | 3 No |
Answer / nitika
SELECT MAX(SAL) FROM EMPLOYEE WHERE SAL<(SELECT MAX(SAL)
FROM EMPLOYEE);
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / hasnain hameed
select max(salary)
from emp
where salary < (select max(salary) from emp)
order by salary desc;
i think this is correct answer all of above because it take
less time to execute. retrive the answer quickly.
| Is This Answer Correct ? | 6 Yes | 4 No |
Answer / kirti
Very simple answer: Arrange the top two salaries in
decending order. Select the mininum salary.
Select min(salary) from Employee where salary in(select top
2 salary from employee order by salary desc)
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / anupam274
use AdventureWorks
select * from HumanResources.EmployeePayHistory e where
2 = (select count(distinct Rate) from
HumanResources.EmployeePayHistory where e.Rate<=Rate)
select * from HumanResources.EmployeePayHistory e where
4 >(select count(distinct Rate) from
HumanResources.EmployeePayHistory where e.Rate<=Rate)
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / malli
select max(sal) from emp where sal<(select max(sal) from emp);
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / gaurav mishra
The answer query is......
Select max(sal) from emp a where (&N-1) in(select count
(distinct(b.sal)) from emp b where a.sal<b.sal);
| Is This Answer Correct ? | 5 Yes | 4 No |
Answer / mallikarjuna
select max(sal) from emp where sal<(select max(sal) from emp);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sandeep
select top(1) a.name
from
(
select top(2) name,salary
from
employee
order by salary desc
)a
order by a.salary asc
| Is This Answer Correct ? | 1 Yes | 0 No |
How is Oracle 10g helpful when compared to oracle 9i and what is grid computing
check whether all the emp numbers are indeed unique.
What are Lexical Parameters.How They are used in Reports 6i
how to shut down the server with 'mysqladmin'? : Sql dba
What are the different types of dbmss?
How to use sql statements in pl/sql?
Can we create index on primary key?
What is an Exception ? What are types of Exception ?
What is the difference between nvl function, ifnull function, and isnull function?
if table named a is there and 4 records are there then how to swap (1 and 3) and (2 and 4) records at a time
what is the difference between cursor FETCH and FOR LOOP ?
3 Answers CG-VAK, Tech Mahindra,
What is mutating table?
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)