Search This Blog

Thursday, June 28, 2007

Retrieve only the Nth row from a table


SQL> select * from taj order by sal desc;

NAME SAL
-------------------- ----------
CEO 10000
MANAGER 8000
IT MANAGER 7000
PROGRAMMER 5000
SALESMAN 3000
SALESMAN 3000
OFFICEBOY 1000
OFFICEBOY 1000

8 rows selected.

Note: Select 6th hightest salary

SQL> select * from (
2 select name,sal,rownum rn from taj where rownum < 7)
3 where rn = 6;

NAME SAL RN
-------------------- ---------- ----------
OFFICEBOY 1000 6

No comments: