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:
Will be sorted in the following order:
The SQL statement I'm currently using is:
SELECT name, assignment_id FROM GrammarAssignments ORDER BY name COLLATE NOCASE
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.
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.
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.
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.).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With