XxGoliathusxX XxGoliathusxX - 2 months ago 8
Android Question

Android Sqlite Order by two regulators

I have an obstacle in my sqlite query. I would like to select a specific entry.
It should be selected the one, which has the latest date. if multiple entries have the same date, it should be picked the one with the highest ID.

Current query:

String query = "SELECT * FROM " + TABLE_BODY + " ORDER BY " + COLUMN_DATE + " DESC LIMIT 1";


NOTE:
COLUMN_DATE
domain is
long
.

So currently the one with the latest date is picked. How to upgrade it?

Answer

Try this:

String query = "SELECT * FROM " + TABLE_BODY + " ORDER BY " + COLUMN_DATE + " DESC, " + COLUMN_ID + " DESC LIMIT 1";
Comments