how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / sudha
select max(sal) from emp where sal <(select max(sal) from
emp);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / pranav damele
All the above one works with Oracle; this one is for MYSQL
second highest :
mysql> select * from employee group by salary desc limit 1,1;
limit 1,1; first '1' means that bring cursor to the end of record and the next '1' means number of records to be printed after the cursor position.
third highest:
mysql> select * from employee group by salary desc limit 2,1;
limit 2,1; '2' means that bring cursor to the end of 2nd record and the next '1' means number of records to be printed after the cursor position.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / mohamed hussain
select salary from
(select salary,Dense_RANK() over (Order by salary desc) as
Level from salary) TMP
where Level=@Level
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / esakki
select max(salary) from employee where salary not in (select
top 1 salary from employee order by salary desc )
change 1 to 2,3,4,......like that for 3rd max ,4th max
salary.....
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / prashanth
select max(sal) from employee where sal<(select max(sal)
from employee)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ashwini
select top 1 salary from emp where salary in (select top 2
salary from emp order by salary asc) order by salary desc
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / naveen r kumar
SELECT Max(salary) FROM TABLE
WHERE salary NOT IN (SELECT Max(salary) FROM TABLE);
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / jhansi
select max(sal) from emp where sal<any(select max(sal) from
emp)
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sankar
select * from emp where sal=(select max(sal) from emp where
sal not in(select max(sal) from emp))
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / pramila
not only seceond highest . you can retrieve 2nd , 3rd.....
highest salary form this query
select min(Salary) from
(select distinct top 2 Salary from tblCategory order by
Salary desc) as tblCategory
| Is This Answer Correct ? | 1 Yes | 0 No |
what is offset-fetch filter in tsql? : Transact sql
What is a trigger ?
11 Answers Accenture, BirlaSoft,
What does (+) mean in sql joins?
What is an exception in pl/sql?
Can there be more than one function with a similar name in a pl/sql block?
What is difference between ms sql and mysql?
Is oracel sql developer written in java?
Why partition by is used in sql?
Explain the PL/SQL compilation process.
Explain the two type of Cursors ?
How do I install sql?
Where is sql database stored?
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)