lokoxumusu
lokoxumusu

Reputation: 71

Sort Cursor by 3 columns

How can I use a Cursor with nBD.query to ORDER BY column1 ASC, then column2 ASC and finally by column3 in order ASC too.

Cursor D = nBD.query(NOMBRE_TB, columnas, null, null, null, null, column1, null);

In SQL is:

Cursor c = nBD.rawQuery("SELECT * FROM " + NOMBRE_TB + " ORDER BY " + COLUMN1 + " ASC, " + COLUMN2 + " ASC, " + COLUMN3 + " ASC", null); 

but I'd like to use the cursor D.

Upvotes: 0

Views: 237

Answers (2)

Rohan Kandwal
Rohan Kandwal

Reputation: 9336

You need to add multiple Order By clause in a single string

String order = "column1 ASC, column2 ASC, column3 ASC";
Cursor D = nBD.query(NOMBRE_TB, columnas, null, null, null, null, order, null);

replace column with real column names. This will make your query to be sorted in way you desire.

Upvotes: 0

Anatol
Anatol

Reputation: 961

String orderBy = COLUMN1 + " ASC, " + COLUMN2 + " ASC, " + COLUMN3 + " ASC";
Cursor D = nBD.query(NOMBRE_TB, columnas, null, null, null, null, orderBy, null);

Upvotes: 2

Related Questions