how to find the second highest salary from emp table?
Answers were Sorted based on User's Feedback
Answer / r.arjunarao
select a.sal from emp a where 2=(select count(distinct(b.sal)) from emp b where b.sal>=a.sal)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rakesh a.
select Amount from PurchaseOrderDetail pod where
1=(select COUNT(amount) from PurchaseOrderDetail pod2 where pod2.Amount>pod.Amount)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / jayshree
select max(sal) from table_name where sal not in (select
max(sal) from table_name)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / tanmoy
SELECT MIN(sal) FROM (SELECT sal FROM emp ORDER BY sal DESC LIMIT 2) AS a ;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / surya
Select max(sal) from employee where sal not in(select max
(sal) from employee)
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / hemanth kumar
select salary from employees where rowid=(select rowid from
employees where rownum<=2
minus
select rowid from employees where rownum<2)
order by salary
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manoj
select * from emp
where
sal=(select MAX(sal) from emp
where
sal<(select MAX(sal)from emp))
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vinod dubey
select * from emp
where sal = (select max(sal) from emp where sal <>(select max(sal) from emp));
it will defiantly work
best of luck
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / nevin
select min(salary) from (select top 2 sal from table_name order by sal desc)salary
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ram achare
for 2nd highest salary
select sal from(select distinct sal from emp order by sal desc limit 2)emp order by salary limit 1;
for 3rd highest salary
select sal from(select distinct sal from emp order by sal desc limit 3)emp order by salary limit 1;
| Is This Answer Correct ? | 0 Yes | 0 No |
Are sql database names case sensitive?
What is an exception in pl/sql?
What is record data type?
Can a composite key be null?
Is and as keyword in pl sql?
Can primary key be changed?
Show the two pl/sql cursor exceptions.
What are the different ways to optimize a sql query?
How can we avoid duplicating records in a query?
What is cursor and its types?
What is user define exception and example
What is write ahead logging in sql server?
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)