select Nth highest salary by using rownum
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
What do you mean by Correlated subquery in database?
How to stop superserver service on linux using only firebird tools?
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
How to determine who is and change the owner of database?
what is s/w lifecycle?
What do you mean by aggregate and scalar functions in dbms?
How to prevent concurrent access to my data?
What is a logical backup ?
What are the two types of indexes and explain them in detail? Or what's the difference between clustered and non-clustered indexes?
What is system r? How many of its two major subsystems?
What is an advantage of a database?
Define "correlated subqueries".