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 privilege is needed for a user to create views in oracle?
How to check the oracle tns settings?
What are a query and state the different types of queries and their uses?
What happens in oracle commit?
What are the built-in functions used for sending Parameters to forms ?
ur a sql devoloper...what is the process in ur company for finding the database BUGS .. seperate DB testers are there? or devr.s are manage? if DB TESTERS in there what is the process
Explain an extent?
What are the types of partitions in oracle?
Is a rollback possible to any savepoint?
In SAP ECC 6.0 , under DB02 tcode , Tablespace name to be explain stepy step all the col
Hi this srilatha. I comlpeted my Oracle-hrms. can u provide me interview questions on Core hr, payroll,sshr,OLM etc..
What is oracle rowcount?
Explain oracle insert into command?
What is a trigger and what are its types?
How to create a table index in oracle?