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.

Share:
10,502
mixkat
Author by

mixkat

Updated on June 07, 2022

Comments

  • mixkat
    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
    mixkat over 13 years
    Cheers for the reply mate...the other method was easier though :)
  • plowman
    plowman almost 13 years
    I 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 the ASC and only specify the direction when it is DESC.
  • aaz
    aaz almost 13 years
    @unchek — Also try COLLATE NOCASE ASC.
  • Surya Wijaya Madjid
    Surya Wijaya Madjid almost 12 years
    @plowman Just like aaz said, the ASC or DESC should be after the NOCASE.