Select the last line

Please, how can I get the latest in the android database? I am using Sugar ORM library to abstract the whole db operation, but I cannot figure out how to get the oldest record on the db.

+3


source to share


2 answers


You need to order some timestamp if you have one, or by id if auto-incrementing, and only take the first result:



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

      

+12


source


Basic algorithm

Get a list of all objects from the database
Take the one with the "maximum" date

      



I'm not familiar with Sugar ORM, so I don't know how to do this with this particular library, other than its very encoding. The SQL query for this would be pretty simple.

0


source







All Articles