Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following table structure ,

name || description || timestamp varchar varchar date

time stamp column consists of time the row is added

Now i need to fetch the recently entered 5 records .. How should i query the table .

Note: i am using oracle 10g

Update :

select * from table orderby timestamp desc where rownum<6

Is that right approach ??

Thanks in advance !!

share|improve this question

closed as off-topic by Mark Storey-Smith, RolandoMySQLDBA, Max Vernon, Michael - sqlbot, Kin Apr 11 '14 at 14:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Mark Storey-Smith, RolandoMySQLDBA, Max Vernon, Michael - sqlbot, Kin
If this question can be reworded to fit the rules in the help center, please edit the question.

What did you try yourself? – Colin 't Hart Feb 25 '14 at 8:36
up vote 2 down vote accepted

Because the where clause is applied first, and the order by is applied to the results, you need to use a subselect as follows:

select * from (
  select *
  from table
  order by timestamp desc
where rownum <= 5;
share|improve this answer

Why don't you try:

       `Select * From my_table
       Where Row_number<6
       Order by Timestamp Desc:

` I think it will work

share|improve this answer
Thanks will try and update . i didnt downvote your answer – San Krish Feb 25 '14 at 9:08
This won't work: the where clause is applied first and then the order by. – Colin 't Hart Feb 25 '14 at 9:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.