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


Please Help Members By Posting Answers For Below Questions

How many data types are supported?

615


How do I uninstall oracle 11g?

558


Why cursor variables are easier to use than cursors?

570


What is a relational database management system?

677


What is Library Cache in Oracle?

641






What does sharding mean?

539


Why do we need integrity constraints in a database?

586


How to set a transaction to be read only in oracle?

581


How to install oracle database 10g xe?

562


Explain the blob datatype?

618


What do you mean by group by clause?

563


What is the difference between translate and replace in oracle?

650


Explain the use of record option in exp command.

533


In AP we done Customizations for Late Payments Charges. For Reporting Purpose What are the Documents Prepared for Customer Understanding??

1205


What is an oracle tablespace?

607