Write a query to get 2nd maximum salary in an employee table ?
Answers were Sorted based on User's Feedback
Answer / m
select max(sal) from emp where sal<(select max(sal) from
emp))
| Is This Answer Correct ? | 222 Yes | 39 No |
Answer / kotravel. b
SELECT MAX(SAL) FROM EMPLOYEE WHERE SAL<(SELECT MAX(SAL)
FROM EMPLOYEE);
THIS will surly give 2^nd max sal ok this correct ans ok....
| Is This Answer Correct ? | 85 Yes | 13 No |
Answer / anil_abbireddy
select * from emp a where 2=(select count(distinct sal)
from emp b where a.sal<=b.sal)
| Is This Answer Correct ? | 44 Yes | 12 No |
Answer / sohail
select empno,ename,sal
from (select ename,empno,sal,dense_rank()
over(order by sal desc)topn
from emp)
where topn=2
| Is This Answer Correct ? | 69 Yes | 46 No |
Answer / anil_abbireddy
select * from emp a where 2=(select count(distinct sal)
from emp b where a.sal<=b.sal)
| Is This Answer Correct ? | 30 Yes | 8 No |
Answer / venkat
select max(sal) from emp where sal<(select max(sal) from
emp);
| Is This Answer Correct ? | 19 Yes | 5 No |
Answer / khandu shinde
select a.sal
from (
select sal ,rownum no
from (
select distinct sal
from emp
order by sal desc
)
) a
where a.no=2
| Is This Answer Correct ? | 16 Yes | 6 No |
Answer / abhay
Select Max(Sal)
From Emp E
Where E.Sal < (Select Max(Sal) From Emp)
| Is This Answer Correct ? | 9 Yes | 1 No |
Answer / uday
Hi friends i think it is surely work because i worked for this.
select * from emp e where 1=(select count(distinct d.esal)
from emp d where d.esal>e.esal)
any one plz try if it's not work
plz let me know.
uday_testing@yahoo.co.in
| Is This Answer Correct ? | 7 Yes | 3 No |
Answer / wei
The best answer should be the first one, this is because
the sql statement accesses table emp only once.
| Is This Answer Correct ? | 9 Yes | 6 No |
What are records give examples?
What is set serveroutput on in pl sql?
Which software is used for pl sql programming?
Explain lock escalation? : Transact sql
How can we overcome recursive triggers in SQL?
Why truncate is faster than delete?
What is the difference between a database and a relational database?
i have a table like this. cityno cityname mails 1 BANGALORE 8KM 2 HSR LAYOUT 20KM 3 MEJISTIC 30KM 4 JAYADEVA 55KM 5 ITPL 80KM 6 HEBBAL 115KM I HAVE DATA LIKE THIS I WANT O/P LIKE THIS DISTANCE NO.OFCITY 0-50KM 3 51-100KM 2 101-150KM 4 AND SO ON pls give me answer. i want urgent
What are field types?
what is row? : Sql dba
Is trigger a stored procedure?
Why use subqueries instead of joins?
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)