I have data in my database like this:
Alice
anderson
Beatrice
benny
Carmen
calzone
Using this code:
mDb.query(DATABASE_NAMES_TABLE, new String[] { KEY_ROWID,
KEY_NAME }, null, null,
null, null, KEY_NAME+ " ASC");
or this code with the filter being "":
mDb.query(true, DATABASE_NAMES_TABLE, new String[] { KEY_ROWID,
KEY_NAME }, KEY_NAME + " LIKE ?",
new String[] { filter+"%" }, null, null, null,
null);
It sorts the above data like this:
Alice
Beatrice
Carmen
anderson
benny
calzone
Is this normal behavior? How do I get it to sort to the above order where all the As and Bs and Cs are together? Thanks.
Introduction to SQLite ORDER BY clause The ORDER BY clause comes after the FROM clause. It allows you to sort the result set based on one or more columns in ascending or descending order. In this syntax, you place the column name by which you want to sort after the ORDER BY clause followed by the ASC or DESC keyword.
Discussion: Use the ORDER BY keyword and the name of the column by which you want to sort. This way, you'll sort the data in ascending order by this column. You could also use the ASC keyword to make it clear that the order is ascending (the earliest date is shown first, the latest date is shown last, etc.).
Syntax: SELECT * FROM table_name ORDER BY column_name; For Multiple column order, add the name of the column by which you'd like to sort records first. The column that is entered at first place will get sorted first and likewise.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
SQL uses ASCII location to sort so you'd use "COLLATE" in some fashion...
Something in the nature of:
ORDER BY YourColumn Collate NOCASE
or
ORDER BY YourColumn Collate SQL_Latin1_General_CP850_BIN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With