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

前端 未结 3 1290
悲哀的现实
悲哀的现实 2020-11-28 03:37

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:<

相关标签:
3条回答
  • 2020-11-28 04:25
    SELECT * FROM NOTES ORDER BY UPPER(title)              
    
    0 讨论(0)
  • 2020-11-28 04:40

    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
    
    0 讨论(0)
  • 2020-11-28 04:40

    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;
    
    0 讨论(0)
提交回复
热议问题