Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get last 3 rows

RanieriOct 6 2009 — edited Oct 6 2009
Hello,

I'm trying to get the last 3 rows of a table ordened by task_id, but it always return the first lines ordened... I'm using the query below:

Task table:
task_id | Comment
1 | comment 1
2 | comment 2
3 | comment 3
4 | comment 4
5 | comment 5
6 | comment 6

select task_id, comment
from tasks
where rownum <= 3
order by task_id desc

the result is always returning the first three lines (1,2,3) and it's not what I want, I want the last 3 lines (4,5,6)...
I think my problem is about rownum use, but I don't know what to do :(

I appreciate any help.
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 3 2009
Added on Oct 6 2009
1 comment
599 views