Write a query to get 2nd maximum salary in an employee table ?
Answers were Sorted based on User's Feedback
Answer / nagarjuna.reddy
select max(sal) from emp where sal <> (select max(Sal) from
emp)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sandip
SELECT MAX(SAL) FROM EMPLOYEE WHERE SAL<(SELECT MAX(SAL)
FROM EMPLOYEE);
I don't think this will work correct me if i am
wrong.Correct one is-------
SELECT MAX(SAL) as SAL FROM EMPLOYEE WHERE SAL<(SELECT MAX(SAL)
FROM EMPLOYEE);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sandip
SELECT MAX(SAL) FROM EMPLOYEE WHERE SAL<(SELECT MAX(SAL)
FROM EMPLOYEE);
The correct one is.......
SELECT MAX(SAL) as SAL FROM EMPLOYEE WHERE SAL<(SELECT MAX(SAL)
FROM EMPLOYEE);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / pramod majhi
select max(salary) from employees where salary<(select
max(salary) from employees);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sushma
SELECT * from
(SELECT * FROM emp ORDER BY sal DESC)
WHERE rownum <= 2
MINUS
SELECT * from
(SELECT * FROM emp ORDER BY sal DESC)
WHERE rownum < 2
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / debasish sinha
select ename,sal,deptno
from emp
where sal =
(
select max(sal)
from emp
where level=2
connect by prior sal>sal
group by level
)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / veera
SELECT * FROM EMP A WHERE &N-1=(SELECT COUNT(DISTINCT SAL) FROM EMP B WHERE A.SAL<B.SAL) ORDER BY SAL
Pass Paramenter :2..it will give the 2nd maximum salary
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / lalit raghuvanshi
I got the solution:
Multiple Sql server queries to get second,third,fourth or nth highest/maximum salary from employee table
http://www.webcodeexpert.com/2014/08/sql-server-query-to-get.html
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ashish jain
select Salary from
(
select salary,ROW_NUMBER() over (order by salary desc) as rownum from Emp group by salary) temp
where rownum=2
Note :It can be used to get any highest salary, just use where rownum=nth salary
| Is This Answer Correct ? | 0 Yes | 0 No |
PL/SQL allocates memory for the variable's at runtime or at compile time
what is the functionality of the function htmlentities? : Sql dba
What are the syntax and use of the coalesce function?
what is recursive stored procedure? : Sql dba
Can i possible to see Table Details ? Ex : Table Name Date Time User Emp May/18/2010 12:59pm Scott
What is the difference between jpql and sql?
What are advantages of Stored Procedures?
What is information schema in sql?
How do I edit a stored procedure?
why should required for Indexed by table in pl/sql
Why do we need pl sql?
What jobs use sql?
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)