how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / naveed saleh
You can use this for getting nth highest salary from
Employee table as follows
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / anantkreshna v
select max(sal) from emp_table where sal < (select max(sal)
from emp_table);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mona thakur
SELECT *
FROM emp
WHERE salary < (
SELECT max( salary )
FROM emp )
ORDER BY salary DESC
LIMIT 1
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / kishor
select max(salary ) from employee
where
sal<(select max(salary)from employee)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / vijay shegokar
select * from employee where salary=(select max(salary) from
employee where salary not in (select max(salary) from
employee));
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / vijay kintali
select e1.ename,e1.sal from emp e1 where n=(select count
(distinct e2.sal) from emp e2 where e1.sal<=e2.sal);
Note:n here is nth highest salary.......
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / arvind
select max(salary) from table_name where sal<(select
max(salary) from table_name)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / bharat puri
select top 2 (salary) from emp
order by salary desc
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / gurvinder
select max(sal)from emp where sal in(select sal from emp minus select max(sal) from emp);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sankar sasmal
select distinct sal from emp e where 2=(select count(distinct sal)from emp s where e.sal<=s.sal)
| Is This Answer Correct ? | 1 Yes | 0 No |
1> how are u debugging in plsql ? 2> how to connect oracle database from unix. is there ne way other than using sqlplus ?
What is a primary key? Explain
How to use transactions efficiently : transact sql
What does the acronym acid stand for in database management?
Explain the order of sql statement execution?
When is the update_statistics command used?
What is database white box testing and black box testing?
How is pl sql different from sql?
What is sql key?
Inline the values in PL/SQL, what does it mean.?
How do I make sql search faster?
What cursor type do you use to retrieve multiple recordsets?
17 Answers Apollo, CTS, IonIdea, Microsoft, Oracle, TCS, Vmoksha, Wipro,
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)