views:

135

answers:

2

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
+3  A: 

You can just convert everything to lowercase for the purposes of sorting:

SELECT * FROM NOTES ORDER BY LOWER(title);

If you want to make sure that the uppercase ones still end up ahead of the lowercase ones, just add that as a secondary sort:

SELECT * FROM NOTES ORDER BY LOWER(title), title;
Chad Birch
I'm sorting by multiple columns, do I have to put the LOWER around each one?
CodeFusionMobile
Yes, there's no way to change the behavior of ORDER BY to be case-insensitive.
Chad Birch
+4  A: 

You can also do ORDER BY TITLE COLLATE NOCASE.

dan04