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

SqlSqliteSortingSql Order-By

Sql Problem Overview


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

Sql Solutions


Solution 1 - Sql

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

Solution 2 - Sql

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;

Solution 3 - Sql

SELECT * FROM NOTES ORDER BY UPPER(title)              

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCodeFusionMobileView Question on Stackoverflow
Solution 1 - Sqldan04View Answer on Stackoverflow
Solution 2 - SqlChad BirchView Answer on Stackoverflow
Solution 3 - SqlMd ShahriarView Answer on Stackoverflow