How to display a list in descending order using query () instead of rawQuery ()? android

I am trying to use the following code to display my list in descending order by KEY_TIME, but it does not work, I also tried rawQuery, but the program was dead after I ran it, please help me find the error, thanks!

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_BODY, KEY_TIME, KEY_CATEGORY, KEY_ALARM}, null, null,null,KEY_TIME+"DESC",null); 
+4
source share
2 answers

Try this code,

 return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_BODY, KEY_TIME, KEY_CATEGORY, KEY_ALARM}, null, null,null,null,KEY_TIME+" DESC"); 
+13
source

Try putting space between KEY_TIME and DESC, it seems they will work together and SQLite will not be able to find the specified key. You will also want it to be in the last position of the request ():

 return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE, KEY_BODY, KEY_TIME, KEY_CATEGORY, KEY_ALARM}, null, null,null,null, KEY_TIME +" DESC"); 

Take a picture

+4
source

All Articles