title: Why doesn't my SQLite cursor return in alphabetical order? (Android)
body: <p>I have been trying to return my table using db.query in alphabetical order based on the name and save as a List for to populate a spinner.</p>
  <p>The db.query does successfully return all the column values, but doesn't return in any order when I try sort.</p>
  <p>The column I want to sort by is COLUMN_COMPANY_NAME (&quot;company_name&quot;) belong to table TABLE__NAME(&quot;companies&quot;). COLUMN_COMPANY_NAME was declared as:</p>
  <pre><code>public static final String TABLE_NAME = &quot;companies&quot;;
  public static final String COLUMN_ID = &quot;company_id&quot;;
  public static final String COLUMN_COMPANY_NAME = &quot;company_name&quot;;
  public static final String COLUMN_EMAIL = &quot;company_email&quot;;
  public static final String COLUMN_PHONE = &quot;company_phone&quot;;
  
  private static final String DATABASE_CREATE = &quot;create table &quot; + TABLE_NAME
  + &quot;(&quot; + COLUMN_ID + &quot; integer primary key autoincrement, &quot;
  + COLUMN_COMPANY_NAME + &quot; varchar(45), &quot;
  + COLUMN_EMAIL + &quot; varchar(45), &quot;
  + COLUMN_PHONE + &quot; integer default 0&quot;
  + &quot;);&quot;;
  
  private SQLiteDatabase db;
  </code></pre>
  <p>I was wanting to use db.query(table, columns, selection, selectionArgs, groupBy, having order) to get all the columns and rows in the database in a cursor:</p>
  <pre><code>protected Cursor Cursor_getAllCompanies(){
      String orderBy = COLUMN_COMPANY_NAME + &quot; Collate NOCASE&quot;;
      return db.query(TABLE_NAME, null, null, null, null, null, orderBy);
  }//if columns = null, default get all columns
  </code></pre>
  <p>So I would expect the rawQuery to be:</p>
  <pre><code>SELECT * FROM companies ORDER BY company_name Collate NOCASE;
  </code></pre>
  <p>I have tried a number of different syntaxes but to no avail. As far as I know the above syntax should return all my columns in (ascending) alphabetical order base on company name, but doesn't.</p>
  <p><strong>The question boils down to: How can I get the db.query to return in an alphabetised order? And why isn't standard order command working?</strong></p>
  <p>Note: There are a number of similar questions that have been answered before, but none of their solutions currently appear to work for me:</p>
  <blockquote>
  <p><a href="https://stackoverflow.com/questions/5958039/sqlite-query-in-non-case-sensitive-alphabetical-order">SQLite Query, Nocase Alphabetical</a></p>
  <p><a href="https://stackoverflow.com/questions/8948435/how-do-i-order-my-sqlite-database-in-descending-order-for-an-android-app">How do I order my SQLite in descending order</a></p>
  <p><a href="https://stackoverflow.com/questions/9089694/android-sqlitedatabase-query-sorting-order">SQLite query sorting</a></p>
  </blockquote>