Reputation: 26387
I have an SQL database with two columns "Message" and "Datetime". I want to know when the last entry was added. I want to get the highest datetime value.
What the most efficient way to query the database in Android/Java to get this value?
Upvotes: 0
Views: 76
Reputation: 1863
Assuming you have SQLite:
If your column is TEXT or REAL then this will give you newest item:
SELECT * FROM Table ORDER BY date(column) DESC Limit 1
or
SELECT * FROM Table ORDER BY datetime(column) DESC Limit 1
or simply
SELECT * FROM Table ORDER BY column DESC Limit 1
Upvotes: 3