How to use SQL Order By statement to sort results case insensitive?

CodeFusionMobile picture CodeFusionMobile · Mar 10, 2010 · Viewed 104.4k times · Source

I have a SQLite database that I am trying to sort by Alphabetical order. The problem is, SQLite doesn't seem to consider A=a during sorting, thus I get results like this:

A B C T a b c g

I want to get:

A a b B C c g T

What special SQL thing needs to be done that I don't know about?

SELECT * FROM NOTES ORDER BY title

Answer

dan04 picture dan04 · Mar 10, 2010

You can also do ORDER BY TITLE COLLATE NOCASE.

Edit: If you need to specify ASC or DESC, add this after NOCASE like

ORDER BY TITLE COLLATE NOCASE ASC

or

ORDER BY TITLE COLLATE NOCASE DESC