Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort a list in ascending order by date from sqlite

I am having a code for retrieving data like this. I wanted to get records with the dates in the ascending order.I tried using "KEY_DATE_TIME ASC" . but it didnt work.

public Cursor fetchAllReminders() {

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
        KEY_BODY, KEY_PHONE,KEY_DATE_TIME}, null, null, null, null, null);
}
like image 804
Ashish Augustine Avatar asked Nov 08 '11 14:11

Ashish Augustine


People also ask

How do I sort ascending in SQLite?

It allows you to sort the result set based on one or more columns in ascending or descending order. In this syntax, you place the column name by which you want to sort after the ORDER BY clause followed by the ASC or DESC keyword. The ASC keyword means ascending. And the DESC keyword means descending.

Can we sort date in SQL?

ORDER BY is a clause in SQL which is used with SELECT query to fetch the records in ascending or descending order from a table. Just like we sort the integer and the string values stored in the column of the tables, similarly, we can sort the dates stored in the SQL table's column.

How do I sort SQLite data in Python?

The ORDER BY statement is a SQL statement that is used to sort the data in either ascending or descending according to one or more columns. By default, ORDER BY sorts the data in ascending order. DESC is used to sort the data in descending order. ASC to sort in ascending order.


1 Answers

Assuming that KEY_DATE_TIME is a String constant holding the name of the db field, the following should work:

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
        KEY_BODY, KEY_PHONE,KEY_DATE_TIME}, null, null, null, null, KEY_DATE_TIME + " ASC");
like image 90
SBerg413 Avatar answered Sep 21 '22 20:09

SBerg413