### Editorial / Best Answer

**nirmal1in**

This can be accomplished in following way:

Example: table - emp

For First n rows:

SELECT * FROM

(SELECT empno,ename,job,row_number() over (order by ename desc) a

FROM emp) x

WHERE x.a < 5 --- say n is 5 display first 5 records

For last n rows:

SELECT * FROM

(SELECT empno,ename,job,row_number() over (order by ename) a

FROM emp) x

WHERE x.a < 5

FROM )WHERE .a<

This query can be used for finding nth row also say n = 5

SELECT * FROM

(SELECT empno,ename,job,row_number() over (order by ename desc) a

FROM emp) x

WHERE x.a = 5

## How do you print the last n rows or the first n rows of a table ?

bharaniprasanthProfile Answers by bharaniprasanth Questions by bharaniprasanth

Questions by bharaniprasanth answers by bharaniprasanth

## Editorial / Best Answer

nirmal1inProfile Answers by nirmal1in Questions by nirmal1in

This can be accomplished in following way:

Example: table - emp

For First n rows:

SELECT * FROM

(SELECT empno,ename,job,row_number() over (order by ename desc) a

FROM emp) x

WHERE x.a < 5 --- say n is 5 display first 5 records

For last n rows:

SELECT * FROM

FROM )WHERE .a<(SELECT empno,ename,job,row_number() over (order by ename) a

FROM emp) x

WHERE x.a < 5

This query can be used for finding nth row also say n = 5

SELECT * FROM

(SELECT empno,ename,job,row_number() over (order by ename desc) a

FROM emp) x

WHERE x.a = 5

## Related Answered Questions

## Related Open Questions