Search code examples
androidsqlitesugarorm

Select last row


Please how can I retrieve the last on an Android DB? I'm using the Sugar ORM library to abstract all db operation but I can't seem to be able to figure out how to retrieve the oldest record on the db.


Solution

  • You have to order by some timestamp, if you have it, or by the ID, if it is autoincrementing, and take only the first result:

    Thing.find(Thing.class, null, null, null, "timestamp DESC", "1");