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
How does oracle handle read consistency?
In what script is snap$ created? In what script is the scott/tiger schema created?
What happens if the update subquery returns multiple rows?
Can we write dml statement in function in oracle?
How to view the tablespaces in the current database?
How to initialize variables with default values?
How to convert characters to times in oracle?
What happens if recursive calls get out of control?
What is Reduced List of Values?
How to rebuild an index in oracle?
hello friends Im doing my final year engineering in B.Tech.. one of uncle said he can provide job in his company if im good in database management. but i have only basic knowledge about database, so like to join database management course in good intuition. so friends kindly help me to get good intuition because its my future.
How to loop through data rows in the implicit cursor?
How to set a transaction to be read only in oracle?
How to write date and time interval literals in oracle?
What is raw datatype?