Android sort sqlite query results ignoring case
10,502
Solution 1
ORDER BY column COLLATE NOCASE;
See http://www.sqlite.org/datatype3.html#collation
Solution 2
On the Android you are given a collation function called LOCALIZED.
When you specify your column, do the following:
CREATE TABLE song(..., title TEXT COLLATE LOCALIZED ASC, ...)
It works great. If you have the Android source code, just do a search for "COLLATE" to see all sorts of examples.
Author by
mixkat
Updated on June 07, 2022Comments
-
mixkat almost 2 years
just wondering if theres a way of sorting the results of a query ignoring case. Cause at the moment fields starting with an upper case letter are sorted and put on top of the list and fields starting with lower case letter are also sorted but are put after the upper case fields.
Thanks -- Mike
-
mixkat over 13 yearsCheers for the reply mate...the other method was easier though :)
-
plowman almost 13 yearsI tried doing this and was getting the error
SQLiteException: near "COLLATE": syntax error: , while compiling: SELECT * FROM table ORDER BY column ASC COLLATE NOCASE
. The solution is to remove theASC
and only specify the direction when it isDESC
. -
aaz almost 13 years@unchek — Also try
COLLATE NOCASE ASC
. -
Surya Wijaya Madjid almost 12 years@plowman Just like aaz said, the ASC or DESC should be after the NOCASE.