0

I have a database from which I would like to take the last 3 records. For example if I had the lines 1,2,3,4,5,6, ... 10,11,12,13,14, I would like 12,13,14 no matter the order (12,13,14 for me is equal to 14,13,12). I tried to follow another question at this link Android SQLite Query - Getting latest 10 records but what I get is just showing the first 3 rows of the database.

This is my query

String query2 ="select * from (select * from USERS order by ID ASC limit 3)";
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
JayJona
  • 469
  • 1
  • 16
  • 41

1 Answers1

4

In any case you can sort by rowid descending and get 3 rows:

select * from USERS order by rowid desc limit 3

If you want to sort by a specific column:

select * from USERS order by columnname desc limit 3
forpas
  • 160,666
  • 10
  • 38
  • 76