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

  • http://stackoverflow.com/questions/311054/how-do-i-select-last-5-rows-in-a-table-without-sorting – Raghunandan Jun 20 '13 at 07: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. – Kelly S. French Jun 20 '13 at 16:58
  • I have editied the question. So it should now not seen as dup –  Jun 21 '13 at 03: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? – Bhargav Dec 10 '15 at 14:36

3 Answers3

1

Try Like:

String query= "SELECT * FROM table ORDER BY id DESC LIMIT 5";
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
0

Try Like This:

String query = "SELECT * FROM table_name LIMIT 0,5";
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Vaibs
  • 1,128
  • 3
  • 16
  • 36
0
SELECT ROWID,* FROM [table] ORDER BY ROWID DESC LIMIT 5
mihail
  • 2,173
  • 19
  • 31