select Nth highest salary by using rownum

Answers were Sorted based on User's Feedback



select Nth highest salary by using rownum..

Answer / srinu

SELECT * FROM EMP WHERE SAL=(SELECT MIN(SAL) FROM ( SELECT
DISTINCT(SAL) FROM EMP ORDER BY SAL DESC) WHERE ROWNUM<'&N');

ANS::

EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
------ ---------- --------- ---------- --------- ----------
---------- ----------
7566 JONES MANAGER 7839 02-APR-81 2975
20

SELECT * FROM EMP WHERE SAL=(SELECT MIN(SAL) FROM ( SELECT
SAL FROM EMP ORDER BY SAL DESC) WHERE ROWNUM<'&N');



EMPNO ENAME JOB MGR HIREDATE SAL
COMM DEPTNO
------ ---------- --------- ---------- --------- ----------
---------- ----------
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7902 FORD ANALYST 7566 03-DEC-81 3000
20

Is This Answer Correct ?    8 Yes 0 No

select Nth highest salary by using rownum..

Answer / siva kumar

select rownum,empno,ename,sal from(select * from emp order by
sal desc)group by rownum,empno,ename,sal having rownum='&n'

Is This Answer Correct ?    6 Yes 2 No

select Nth highest salary by using rownum..

Answer / xxx

SELECT * FROM EMP WHERE N=(SELECT COUNT(DISTINCT SAL) FROM EMP
WHERE SAL>=e.SAL);

Is This Answer Correct ?    3 Yes 0 No

select Nth highest salary by using rownum..

Answer / welcomeashwin

SELECT * FROM HR.EMPLOYEES EMP1
WHERE &N=(
SELECT COUNT(DISTINCT(SALARY))
FROM HR.EMPLOYEES EMP2
WHERE EMP1.SALARY<=EMP2.SALARY
);

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Database Management Interview Questions

What do you mean by Correlated subquery in database?

0 Answers   B-Ways TecnoSoft,


How to stop superserver service on linux using only firebird tools?

0 Answers  


If I delete a table and then rollback it, do the index on the table remains? What if I drop the table and roll back?Do index on the table remains? What if I truncate the table and roll back? Do the index on the table remains

2 Answers   Wipro,


How to determine who is and change the owner of database?

0 Answers  


what is s/w lifecycle?

1 Answers   IBM,






What do you mean by aggregate and scalar functions in dbms?

0 Answers  


How to prevent concurrent access to my data?

0 Answers   HCL,


What is a logical backup ?

3 Answers   Wipro,


What are the two types of indexes and explain them in detail? Or what's the difference between clustered and non-clustered indexes?

0 Answers  


What is system r? How many of its two major subsystems?

0 Answers  


What is an advantage of a database?

0 Answers  


Define "correlated subqueries".

0 Answers  


Categories