ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  Oracle  >>  Oracle General
 
 


 

 
 Oracle General interview questions  Oracle General Interview Questions
 OCI interview questions  OCI Interview Questions
 Architecture interview questions  Architecture Interview Questions
 Oracle Security interview questions  Oracle Security Interview Questions
 Database Management interview questions  Database Management Interview Questions
 Forms Reports interview questions  Forms Reports Interview Questions
 Oracle AllOther interview questions  Oracle AllOther Interview Questions
Question
find out the third highest salary?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: find out the third highest salary?
Answer
# 1
select sal from emp
where sal=(select min(sal) from emp
where sal>(select min(sal) from emp
where sal>(select min(sal) from emp);
 
Is This Answer Correct ?    1 Yes 2 No
Ashutosh Pandey
 
  Re: find out the third highest salary?
Answer
# 2
select sal from emp
where sal = (max(sal) from emp
where sal < (max(sal) from emp
where sal < (max(sal) from emp)));
 
Is This Answer Correct ?    4 Yes 1 No
Lakshmi
 
 
 
  Re: find out the third highest salary?
Answer
# 3
select * from emp e1 where (3-1) = (select count(distinct
(e2.sal)) from emp e2 where e2.sal>e1.sal)
 
Is This Answer Correct ?    3 Yes 3 No
Sanjeev Kumar P
 
  Re: find out the third highest salary?
Answer
# 4
SELECT MIN(sal) FROM emp WHERE 
sal IN (SELECT  distinct TOP 3  sal FROM emp ORDER BY sal DESC)
 
Is This Answer Correct ?    4 Yes 0 No
Biswapratap Singh
 
  Re: find out the third highest salary?
Answer
# 5
select empno,ename,sal from
(select empno,ename,sal from emp order by sal desc)
group by rownum,ename,sal having rownum=&n;
 from this query we can find top nth sal
 
Is This Answer Correct ?    1 Yes 0 No
Husenaiah.b
 
  Re: find out the third highest salary?
Answer
# 6
select max(sal) from emp where sal <(select max(sal)from emp
where sal<(select max(sal) from emp));
 
Is This Answer Correct ?    1 Yes 1 No
Neha
 
  Re: find out the third highest salary?
Answer
# 7
select * from (select e.*,rownum r from (select distinct 
sal from emp order by sal desc) e) where r  = 3
 
Is This Answer Correct ?    3 Yes 0 No
Akshita
 
  Re: find out the third highest salary?
Answer
# 8
donno whether the rest are correct ..but this one is:-
select max(sal) from emp where sal<(select max(sal) from emp
where sal<( select max(sal) from emp));
 
Is This Answer Correct ?    0 Yes 0 No
Arijit
 
  Re: find out the third highest salary?
Answer
# 9
Hi every body,

 I give the standard format Query for this type of top most 
and who are the top n people in the organization like that

If we take EMP table

Select * from EMP A where &n= (select count (distinct 
(sal))   from EMP B where B.sal>A.sal)

If we give n value 1 or 2 or 3….etc then we gets top one, 
top second, and top third person details.

This same query can we use top n people who are earning 
maximum salaries in the Organization 

Select * from EMP A where &n> (select count (distinct 
(sal))   from EMP B where B.sal>A.sal)
 
Is This Answer Correct ?    0 Yes 0 No
Suresh Kumar
 
  Re: find out the third highest salary?
Answer
# 10
Hi every one,

i know that we can get that thr above quer..

one can try using analytic function giving ranks to the 
salary column

select sal,dense_rank() over(order by sal desc) rank from 
emp
 
Is This Answer Correct ?    1 Yes 0 No
Kss
 
  Re: find out the third highest salary?
Answer
# 11
Hi everybody,
This is one way to get the third highest salary
select ROWNUM as RANK from (select * from emp order by sal) 
where ROWNUM<=3
 
Is This Answer Correct ?    1 Yes 0 No
Naveen Kumar
 
  Re: find out the third highest salary?
Answer
# 12
Hi, this query will gives the third highest salary from table

select * from emp e
where 3 = (select count(sal) from emp 
where e.sal < sal);

To dispay 5th highest salary, just change the number 3 to 5.
Like that we can find top N salaries.

I hope i'm not wrong.
 
Is This Answer Correct ?    0 Yes 0 No
Harmeet
 
  Re: find out the third highest salary?
Answer
# 13
select distinct(a.sal) from emp a where &3 = ( select count
(distinct(b.sal) from emp b where a.sal <= b.sal));
 
Is This Answer Correct ?    2 Yes 0 No
Saleem
 
  Re: find out the third highest salary?
Answer
# 14
select *
  from (select distinct sal from emp order by sal desc)
 where rownum <= 3
 
Is This Answer Correct ?    2 Yes 0 No
Swaminathan
 
  Re: find out the third highest salary?
Answer
# 15
SELECT * FROM
(
SELECT EMPLOYEECODE, SAL, Rank() OVER (ORDER BY SAL DESC ) 
RANKNEW FROM EMPLOYEE)
WHERE RANKNEW = 3
 
Is This Answer Correct ?    0 Yes 0 No
Abbas
 
  Re: find out the third highest salary?
Answer
# 16
select e.sal from employee where n-1=(Select count(distinct
sal) from emp where sal>e.sal)


Put n=3 for the 3rd highest salary.
 
Is This Answer Correct ?    0 Yes 0 No
Nehal
 
  Re: find out the third highest salary?
Answer
# 17
Here is the correct query:

select ename,sal from emp e
where 3 = (select count(distinct(sal))+1 from emp 
where e.sal < sal);
 
Is This Answer Correct ?    1 Yes 0 No
Vishal
 
  Re: find out the third highest salary?
Answer
# 18
Guys Few of you have submitted an optimal query.

select distinct sal from emp A where 3 = (select count(sal)
from emp B where a.sal > b.sal)

However the integer 3 will not give the third highest salary
as expected. Point should be noted that the row starts with
zero.

so the actual result will the fourth highest salary with the
above query.
 
Is This Answer Correct ?    0 Yes 0 No
Sudheer
 
  Re: find out the third highest salary?
Answer
# 19
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
Mahesh
 
  Re: find out the third highest salary?
Answer
# 20
SELECT MAX(SAL) FROM EMP WHERE SAL NOT IN (SELECT MAX(SAL) 
FROM EMP UNION SELECT MAX(SAL) FROM EMP WHERE SAL NOT IN
(SELECT MAX(SAL) FROM EMP))
 
Is This Answer Correct ?    0 Yes 0 No
Anirban Mitra
 
  Re: find out the third highest salary?
Answer
# 21
In ORACLE 10g,

SELECT * FROM employee x WHERE 3 = (SELECT COUNT(DISTINCT 
salary)
FROM employee y WHERE x.salary <= y.salary);
 
Is This Answer Correct ?    0 Yes 0 No
Selvaraj Anna University Coe
 
  Re: find out the third highest salary?
Answer
# 22
select name,salary from emp where salary=(select min(sal) 
from (select distinct TOP 3(salary) from emp order by 
salary desc;
 
Is This Answer Correct ?    0 Yes 0 No
Santhoshkumar
 
  Re: find out the third highest salary?
Answer
# 23
In Oracle 9i:
-------------

SQL> SELECT MAX(salary) FROM emp WHERE LEVEL=&no CONNECT BY 
PRIOR Salary>salary;


Enter value for no: 3

old   1: SELECT MAX(SALARY) FROM EMP WHERE LEVEL=&no 
CONNECT BY PRIOR SALARY>SALARY
new   1: SELECT MAX(SALARY) FROM EMP WHERE LEVEL=3 CONNECT 
BY PRIOR SALARY>SALARY

MAX(SALARY)
-----------
     500000

SQL>
 
Is This Answer Correct ?    1 Yes 0 No
Selvaraj Anna University Coe
 
  Re: find out the third highest salary?
Answer
# 24
Guys 
i have executed this query in sql plus.This is correct

Select * from EMP_USER A where n-1 = (select count 
(distinct (sal))   from EMP_USER B where A.sal<B.sal)

where n=3

reason for using n-1 is below:

1.We are using correlated sub query.so sal value from each 
row in outer query(EMP_USER A) is compared with sal of all 
the rows in EMP_USER B

eg:
ENAME   SAL
-----  -----
SMITH   800
KING   5000
FORD   3000

here third highest is 800.so when executing this 800 from 
outer query is compared with 800,5000,3000 in inner query 
which returns a count(distinct(sal) = 2

if you use n instead of n-1 you get a empty result.

Let me know if this is correct
 
Is This Answer Correct ?    0 Yes 0 No
Rajdevar
 
  Re: find out the third highest salary?
Answer
# 25
select sal from emp 
where sal<(select max(sal) from emp 
where sal in (select sal from emp
where sal < ( select max(sal) from emp)))
 
Is This Answer Correct ?    1 Yes 0 No
Joel
 

 
 
 
Other Oracle General Interview Questions
 
  Question Asked @ Answers
 
difference between imlicit cursor and explicit cursor ? Cap-Gemini1
What is the maximum number of CHECK constraints that can be defined on a column ?  3
What are the advantages of Views ?  1
I need to get the values of the previous quarter.how to do this?eg: if my cuurent month is may i need to get the datas of the month jan,feb,march.Can it be done in oracle.I tried with date function q but for the month jan its not retriving the previous quarter(oct-dec).how to solve this.plpz anyone help me? Philips1
What is a data segment ?  1
can a table has a column that has only view data and in other columns we can change data? Secon1
What are joins..how many types of joins are there? TCS8
If a table column has is UNIQUE and has NOT NULL, is it equivalent to a PRIMARY KEY column? IBM6
How to make a Data Backup in oracle ? What is the procedure for creating the dump files in oracle ( any version ) ? Satyam1
what is a view?  3
can you write commit in triggers?  3
What is a Temporary Segment ?  1
what is the difference between simple view and complex view?  4
consider some table with 4 r 5 columns in that 1 col is DATE type. The data is like that,For each date in that col some 3 fields r there but all the records r having different data. Now i want to display all the columns by performing grouping on the date field ( as SELECTION Operator(*) cannot be used with group function having only one "group by clause". how to do this? can any one help me in finding out the solution plss?  1
pls explain connect by prior with example and its real time use  2
What is a Schema ?  2
What are the Characteristics of Data Files ?  1
What is the effect of setting the value "ALL_ROWS" for OPTIMIZER_GOAL parameter of the ALTER SESSION command ?  1
How can we Update a table with out using UPDATE command?  1
Ho to insert no. of records at a time..i mean i want to insert 100 records at a time into a table  3
 
For more Oracle General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com