Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android/java Sqlite: How to retrieve max datetime?

Below is the snapshot of what I have got as a query from sqlite db.

After googling and reading a number of question around, I have come to know that to retrieve maximum datetime using aggregate functions like max() is not possible as sqlite doesn't support much datatypes but treats datatype as text.

So, I have brought this data in a List or at java level. So how could I now get the maximum datetime from this list.

Is there any direct construct for this format in java. Or do we have something at sqlite level that I coudn't find.

Sqlite returned data

like image 966
Prateek Avatar asked Dec 12 '12 10:12

Prateek


1 Answers

texts can be compared, sorted and ordered in SQLite.

Your format appears to be YYYY-MM-dd hh:mm:ss. Lucky for you, ordering this format result in ordering by date.

just

select current_test_id from someTable order by test_datetime desc limit 1

or

select current_test_id, max(test_datetime) from someTable

(or something, not entirely sure for the second one)

like image 66
njzk2 Avatar answered Nov 11 '22 16:11

njzk2