Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite sort special characters alphabetically

Tags:

android

sqlite

I'm building an application that is used to teach people French. When I try to sort some French words do not end up where I intended them to be, for example:

  • Aller
  • Boire
  • En
  • Être
  • Vouloir

Will be sorted in the following order:

  • Aller
  • Boire
  • En
  • Vouloir
  • Être

The SQL statement I'm currently using is:

SELECT name, assignment_id FROM GrammarAssignments ORDER BY name COLLATE NOCASE
like image 961
Jon Koops Avatar asked Nov 06 '12 10:11

Jon Koops


People also ask

How do I sort alphabetically in sqlite?

The ORDER BY clause comes after the FROM clause. It allows you to sort the result set based on one or more columns in ascending or descending order. In this syntax, you place the column name by which you want to sort after the ORDER BY clause followed by the ASC or DESC keyword. The ASC keyword means ascending.

How are special characters sorted?

They are probably sorted by their corresponding value in the ASCII table. The actual sorting algorithm is probably more complex and also takes any other Unicode character into account. But the character shown in your examples appear in the ASCII table and their values (at least the order) also maps to Unicode.

How to sort data in ascending order in SQLite?

By default, ORDER BY sorts the data in ascending order. DESC is used to sort the data in descending order. ASC to sort in ascending order.

How do I sort data in sqlite database?

Use the ORDER BY keyword and the name of the column by which you want to sort. This way, you'll sort the data in ascending order by this column. You could also use the ASC keyword to make it clear that the order is ascending (the earliest date is shown first, the latest date is shown last, etc.).


1 Answers

Just in case some one else comes across this post, I ran into the same issue and tested it. The below should do the trick of sorting depending on the locale as well as sorting case insensitive.

SELECT name, assignment_id FROM GrammarAssignments ORDER BY name COLLATE LOCALIZED ASC
like image 74
velval Avatar answered Oct 11 '22 00:10

velval