Kollation

To sort German umlauts Ä, Ö, and Ü or ä, ö, and ü correctly in a MySQL database, you need the appropriate collation (character set) for the relevant column.

For example, suppose we have five countries that we want to display in the correct sort order (Andorra, Australia, Cyprus, Austria, and Ethiopia). With the default collation latin1_swedish_ci, an attempt to sort the countries in ascending order might produce the following result:

Andorra
Australia
Cyprus
Ethiopia
Austria

With the latin1_general_ci collation, we get a better approximation, with "Ä" sorted after "A":

Andorra
Australia
Ethiopia
Austria
Cyprus

Alternatively, with the latin1_german2_ci or utf8_german2_ci collation, "Ä" is treated as "AE":

Ethiopia with Ä
Andorra
Australia
Austria
Cyprus

However, the correct sorting is achieved with the latin1_german1_ci and utf8_general_ci collations:

Andorra
Ethiopia with Ä
Australia
Austria
Cyprus

In conclusion: The collation (e.g. german1_ci) determines how different characters are compared within the selected character encoding (e.g. utf8). When sorting words with lowercase and uppercase initial letters, they are treated equally by the two collations mentioned above (ci stands for "case insensitive").

... back to the blog