Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Query in non case sensitive alphabetical order [duplicate]

All I want to do is grab the stuff in alphabetical order and ignore the capital letters.

db.rawQuery("SELECT " + catName + " FROM "+tableName+" ORDER BY "+catName+" ASC COLLATE NOCASE;", null); 

This is the code I'm using above, but it always gives me an SQLite exception saying that COLLATE is a syntax error.

android.database.sqlite.SQLiteException: near "COLLATE": syntax error: , while compiling: SELECT Artist FROM testTable COLLATE NOCASE ASC

like image 216
Anthony Honciano Avatar asked May 11 '11 00:05

Anthony Honciano


People also ask

How do you make case insensitive comparisons in SQLite?

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.

Is SQLite query case sensitive?

The important point to be noted is that SQLite is case insensitive, i.e. the clauses GLOB and glob have the same meaning in SQLite statements.

How do I use wildcards in SQLite?

SQLite LIKE examplesTo find the tracks whose names start with the Wild literal string, you use the percent sign % wildcard at the end of the pattern. To find the tracks whose names end with Wild word, you use % wildcard at the beginning of the pattern.

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.


1 Answers

COLLATE goes before the order direction:

db.rawQuery("SELECT " + catName             + " FROM " +tableName          +" ORDER BY "+catName+" COLLATE NOCASE ASC;", null); 

But you don't need the ASC -- that's the default so you could just as well use:

db.rawQuery("SELECT "+ catName              +" FROM "+ tableName          +" ORDER BY "+ catName +" COLLATE NOCASE;", null); 
like image 145
OMG Ponies Avatar answered Sep 25 '22 15:09

OMG Ponies