开发者

Sorting SQLite items alphebetically regardless of case?

开发者 https://www.devze.com 2023-02-20 19:01 出处:网络
I am retrieving items from a SQLite database and displaying them in a UITableview,I am using the following SQL command to get the information.

I am retrieving items from a SQLite database and displaying them in a UITableview, I am using the following SQL command to get the information.

SELECT DISTINCT Name FROM Food

Everything works fine except I notice that uppercase items come sorted first, then lowercase items, which messes up the whole alphabetical setup that I am trying to accomplish. I have looked into various SQL commands, but I couldn't find anything that would change this. I am new to working with databases, so any advice would be welcomed.

Example of problem开发者_StackOverflow中文版:

  • Apple
  • Basket
  • Cheese
  • beets

What I would like:

  • Apple
  • Basket
  • beets
  • Cheese


order by lowercase:

SELECT DISTINCT Name
FROM Food
ORDER BY lower(Name)


You can also use the built-in NOCASE function for case insensitive matching,
but it works only for ASCII characters.

SELECT DISTINCT Name
FROM Food
ORDER BY Name ASC COLLATE NOCASE


Why not just use SELECT DISTINCT Name FROM Food ORDER BY Name ASC?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号