Android sql – how do you order your sql query by multiple columns

android

I am currently working on an Android project in Eclipse and i am having problems with my SQL query.

I am trying to order the query by more than two columns, currently i am doing it by KEY_DAY_ID but i want to also do it by KEY_START_TIME, but i can't get it to work

my query currently looks like this:

Cursor cursor = db.query(TABLE_SESSION, new String[] {KEY_ID, KEY_MODULE_CODE, 
            KEY_DAY_OF_WEEK, KEY_START_TIME, KEY_DURATION, KEY_SESSION_TYPE, KEY_ROOM},
            null, null, null, null, KEY_DAY_ID  + " ASC");

Please let me know your thoughts. Thank you in advance!

Best Answer

The last parameter in db.query() method is the order by clause (without the "order by"). All you need to do is separate both columns by a ",". So it would look like:

Cursor cursor = db.query(TABLE_SESSION, new String[] {KEY_ID, KEY_MODULE_CODE, 
        KEY_DAY_OF_WEEK, KEY_START_TIME, KEY_DURATION, KEY_SESSION_TYPE, KEY_ROOM},
        null, null, null, null, KEY_DAY_ID + " ASC, " + KEY_START_TIME  + " ASC");