Android use OrderBy in ORMLite

4.2k views Asked by At

i'm trying to use chaining orderBy for this code:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).query();

i can not find good document for how to use orderBy() chain for this code befor using .query() for example this code:

GenericRawResults<String[]> raw_result =G.messagesListsDao.queryRaw("SELECT * FROM messageslist WHERE group_id = " + group_id + " ORDER BY received_date");

to:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).orderby("id",false).query();
1

There are 1 answers

2
Clayton Oliveira On BEST ANSWER

You can call orderBy() more than once, like this:

List messages = G.messagesListsDao.queryBuilder().where().eq("group_id", group_id).orderBy("id",false).orderBy("received_date",false).query();

This is covered by the documentation. To quote:

Add "ORDER BY" clause to the SQL query statement to order the results by the specified column name. Use the ascending boolean to get a ascending or descending order. This can be called multiple times to group by multiple columns.

Hope it works !