-1

I have combine list which contains red color or not. I want to sort my result as below -

If color is not red then display result Alphabetically. (in continuation of list) ---> If color is red then display rest of element Alphabetically.

I am expecting below result :

// If color is not red then display result Alphabetically

orange A (color is not red & alphabetically order)

blue B (color is not red & alphabetically order)

white C (color is not red & alphabetically order)

black D (color is not red & alphabetically order)

//(in continuation of list) ---> If color is red then display rest of element Alphabetically

red A (color is red & alphabetically order)

red B (color is red & alphabetically order)

red C (color is red & alphabetically order)

To achieve this, i am trying below query :

public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {

        case SORT_BY_ALPHABETICALLY:

            String orderAlphabetically = BY_NAME + " ASC, "
                + BY_COLOR + " ASC";

            return new CursorLoader(ctx,
                    URI,
                    null,
                    null,
                    null,
                    orderAlphabetically);

but above query is not giving expected result.

Buddy
  • 105
  • 1
  • 10

1 Answers1

0

You want to sort by redness first, then by name.

In SQLite, a boolean expression returns either 0 or 1, so this is exactly what you want for sorting:

SELECT ... ORDER BY Color = 'red' ASC, Name ASC;
CL.
  • 173,858
  • 17
  • 217
  • 259