Query to get max and second max in oracle in one query ?

Answers were Sorted based on User's Feedback



Query to get max and second max in oracle in one query ?..

Answer / satish

SELECT SAL FROM (SELECT SAL,DENSE_RANK() OVER(ORDER BY SAL DESC) RANK FROM EMP) WHERE RANK=2;

Is This Answer Correct ?    0 Yes 0 No

Query to get max and second max in oracle in one query ?..

Answer / satish

SELECT SAL SECOND_MAX_SAL FROM (SELECT SAL,DENSE_RANK() OVER(ORDER BY SAL DESC) RANK FROM EMP) WHERE RANK=2;

Is This Answer Correct ?    0 Yes 0 No

Query to get max and second max in oracle in one query ?..

Answer / sunil

select sal from (select dense_rank() over(order by sal) rank
from emp) where rank in(1,2);

In above query you will get both highest and second highest
salary details even there are more people who are getting
highest and second highest salary.

Is This Answer Correct ?    0 Yes 0 No

Query to get max and second max in oracle in one query ?..

Answer / purna chowdary

Select Sal From Emp A
WHERE 1=(Select Count(Sal) From Emp B
WHERE B.Sal>A.sal)
GROUP By Sal Desc

Is This Answer Correct ?    0 Yes 0 No

Query to get max and second max in oracle in one query ?..

Answer / shareef

select ename,empno,sal,r from(select ename,empno,sal,dense_rank() over(order by sal desc) r from emp) where r=3; ----by using dense_rank()

Is This Answer Correct ?    0 Yes 0 No

Query to get max and second max in oracle in one query ?..

Answer / ajit

select max(sal),1 no
from emp
union
select sal,rn from (select sal,rownum rn from emp)
where rn = 2
order by 1 desc;

Is This Answer Correct ?    0 Yes 0 No

Query to get max and second max in oracle in one query ?..

Answer / asdasd

SELECT min(gross) FROM(SELECT distinct(gross) FROM
srbs_staff_pay_dtls ORDER
BY gross DESC) WHERE ROWNUM<=4;

Is This Answer Correct ?    2 Yes 3 No

Query to get max and second max in oracle in one query ?..

Answer / at_avrat_braveheart

select amc&#305;k from göt_tarlas&#305;

Is This Answer Correct ?    2 Yes 3 No

Query to get max and second max in oracle in one query ?..

Answer / abcd

for page break or form feed we use following
&#12; &#x0C; /f (char)12
for nbsp;
(char)10 &#160;

Is This Answer Correct ?    1 Yes 2 No

Query to get max and second max in oracle in one query ?..

Answer / sarmistha mohanty

select * from (
select SAL,
row_number() over (partition by 1 order by SAL DESC)
as rank
from <table name> ) where rank in (1,2)

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More Oracle General Interview Questions

How do we create privileges in oracle?

0 Answers  


What would you use to improve performance on an insert statement that places millions of rows into that table?

1 Answers  


How to do a full database export?

0 Answers  


What is the difference between Outer join and Full outer join?

5 Answers  


What are temporal data types in oracle?

0 Answers  






what is reindexing?

0 Answers   Tata Technologies,


interview questions with answer for cts

0 Answers   Cognizant,


What is blob datatype?

0 Answers  


How to call a stored function in oracle?

0 Answers  


Explain the use of indexes option in imp command.

0 Answers  


I have a table like this Table Name:Products Productid Price 1 10 1 10 2 20 3 30 3 30 But i want to output like this. productid price 2 20. please replay me.

3 Answers   TCS,


What are the general rules on data consistency?

0 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)