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
?
精彩评论