sunil


{ City } hyderabad
< Country > india
* Profession *
User No # 70271
Total Questions Posted # 0
Total Answers Posted # 5

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 41
Users Marked my Answers as Wrong # 19
Questions / { sunil }
Questions Answers Category Views Company eMail




Answers / { sunil }

Question { CTS, 57302 }

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


Answer

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

Question { ABC, 21406 }

how to delete all duplicate records from a table using
subquery?


Answer

delete emp where empno not in(select distinct empno from emp);

For example we have duplicates in empno column then write
query like above...whatever column u want u can write..

Is This Answer Correct ?    0 Yes 11 No


Question { Verizon, 6629 }

what is the querry to get first 10 records from the emp
table?(emp no is the primary key)


Answer

select * from emp where rownum<=10;

or

select * from (select rowid ri,e.* from emp e order by ri)
where ri<=10;

Is This Answer Correct ?    1 Yes 0 No

Question { Oracle, 11958 }

How to Select second Maximum salary in a Table ?


Answer

select max(sal) from table_name where
sal<(select max(sal) from table_name);

or

select sal from(select sal,dense_rank() over(order by sal)
as rnk from table_name) where rnk=2;

Is This Answer Correct ?    7 Yes 4 No

Question { TCS, 7938 }

I have one table :EID,Depid,ename,sal
I want to have max(sal) in each department.


Answer

select depid,max(sal) from group by depid;

Is This Answer Correct ?    33 Yes 4 No