find out the third highest salary?
Answer Posted / rajdevar
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 ? | 13 Yes | 5 No |
Post New Answer View All Answers
What is an oracle recycle bin?
What is materialized view in Oracle?
What is blob data type in oracle?
Assuming that you are an End User How to find that in the payment Batch some of the Invoice was Missing To pay How to find That??
How to put more than 1000 values into an oracle in clause?
What are the attributes that are found in a cursor?
What is meant by joins?
How to view the tablespaces in the current database?
What is the string concatenation operator in oracle?
What is index-organized table in Oracle?
How do I recompile a procedure in oracle?
Is oracle a programming language?
How to define default values for formal parameters?
How to import one table back from a dump file?
Why do we need oracle client?