0

I have a very basic database and my requirement is that whenever the app comesup it should show latest n additions (rows added) in the database. Additions should also cover replacing values in existing rows..

Think of a console where you are showing lastest 100 modifications to the DB.

To keep the size of db small I am not including a timestamp.

Is there anyeasy way to do it

4
  • stackoverflow.com/questions/311054/… Commented Jun 20, 2013 at 7:27
  • He needs to be more specific about his definition of 'last'. The duplicate-link is also ambiguous about 'last'. If they both mean 'the bottom 5 rows' then it's a dup, but remember that SQL doesn't have to insert them in any order so the most recent rows could be at the bottom of the table. Commented Jun 20, 2013 at 16:58
  • I have editied the question. So it should now not seen as dup Commented Jun 21, 2013 at 3:26
  • 1
    This question should not be seen as duplicate anymore, here the @mSO wants to know the last 5 inserted/modified rows in the table, not the last 5 rows that are present in the table. The question given in the link for duplicate doesn't even make sense, logically speaking isn't sql a storage without order? Commented Dec 10, 2015 at 14:36

3 Answers 3

1

Try Like:

String query= "SELECT * FROM table ORDER BY id DESC LIMIT 5"; 
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT ROWID,* FROM [table] ORDER BY ROWID DESC LIMIT 5 

4 Comments

How to get updates in existing rows
if you need to get the last 5 updated rows, you will need to include a timestamp field and update it on every modification on this row.
I see this for first time - unaccepted answer because of changing the topic of the whole question
oops my bad. I didnt used correct terms
0

Try Like This:

String query = "SELECT * FROM table_name LIMIT 0,5"; 

Comments