Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android sort sqlite query results ignoring case

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

like image 208
mixkat Avatar asked Feb 07 '11 01:02

mixkat


People also ask

How do I make SQLite query case insensitive?

To be case insensitive on firstname , write this: select * from tbl where firstname='john' COLLATE NOCASE and lastname='doe' . It's specific to that one column, not the entire where clause.

Are SQLite queries case-sensitive?

Important Note: SQLite only understands upper/lower case for ASCII characters by default. The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range.

Is SQL ORDER BY case-sensitive?

SQL Server is, by default, case insensitive; however, it is possible to create a case-sensitive SQL Server database and even to make specific table columns case sensitive.

How do I sort data in SQLite database?

If you don't specify the ASC or DESC keyword, SQLite sorts the result set using the ASC option. In other words, it sorts the result set in the ascending order by default. In case you want to sort the result set by multiple columns, you use a comma (,) to separate two columns.


2 Answers

ORDER BY column COLLATE NOCASE;

See http://www.sqlite.org/datatype3.html#collation

like image 142
aaz Avatar answered Sep 27 '22 19:09

aaz


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.

like image 21
djunod Avatar answered Sep 27 '22 19:09

djunod