Ryan
Ryan

Reputation: 1465

Sorting SQLite items alphebetically regardless of case?

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:

What I would like:

Upvotes: 0

Views: 598

Answers (3)

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43130

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

Upvotes: 1

Angelo
Angelo

Reputation: 533

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

Upvotes: 0

manji
manji

Reputation: 47978

order by lowercase:

SELECT DISTINCT Name
FROM Food
ORDER BY lower(Name)

Upvotes: 1

Related Questions