how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / dev anand s
select salary from (
select salary, dense_rank() over(order by salary desc) rank from emp) where rank=2;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rajkishore bagwan
simplest method ----
select salary
from employees
order by salary desc
offset n-1 rows fetch next 1 rows only
(replace n with any number it will give you the nth highest salary)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / hitesh
select top 1 salary from t1 where salary in(select top 2
salary from t1 order by salary desc)order by salary asc
| Is This Answer Correct ? | 2 Yes | 3 No |
Answer / sabari
select max(salary ) from emp where salary<(select max
(salary)from emp )
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / sumit sharma
select sal from (select distinct(sal) from emp where sal is
NOT NULL order by sal dsc) where rownum = 2
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / priya
select sal from emp where sal <(select max(sal) from emo)
and rownum<2 order by desc
though rownum which is a pseudo column can be used for
comparisions with relational operators like > or < ,>=, <=
but equalto = may not work in most of the cases..
similarly rowid also.
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / nitin umale
SELECT *
FROM employees
WHERE salary =
( SELECT MIN ( r.salary)
FROM ( SELECT salary
FROM ( SELECT DISTINCT salary
FROM employees
ORDER BY NVL(salary,0) DESC
)
WHERE rownum<3) r
);
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / abhay
select max(sal) from emp where sal< (select max(sal) from
emp)
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / ravi
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n is the nth highest salary
| Is This Answer Correct ? | 0 Yes | 1 No |
Can we use two order by clause in query?
Define tables and fields in a database
What are the limitations of sql express?
write a query that returns first characters of each word in Oracel/Sql pl sql
can we use out parameter in a function?Give an example.
How can we debug in PL/SQL?
How can we schedule the procedure to run automatically ?
A table was given with 3 columns like Manager id,Manager Name and Employee name. Question was to create hierarchy.
Differences between Oracle 9i and 10g (Probably in terms of SQL and PL/SQL)?
How to execute a stored procedure?
what is difference between pass by value and eference by value in oracle plsql
How do I run pl sql in sql developer?
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)