I have a table with field name
, which is in utf8_general_ci
. When I run this query SELECT name FROM users ORDER BY name ASC
I got some strange results. After letter 'S' comes special letter 'Š', which is correct, but after 'Š' comes more letters 'S', which should be before that. Other than that the results are fine. Why is this ordering like this and how should I fix it?
我有一个带有字段名称的表,它位于utf8_general_ci中。当我运行此查询SELECT name FROM users ORDER BY name ASC时,我得到了一些奇怪的结果。字母'S'后面出现特殊字母'Š',这是正确的,但在'Š'之后会出现更多字母'S',这应该在此之前。除此之外,结果还不错。为什么这样订购,我该如何解决?
1 个解决方案
#1
1
The utf8_general_ci
collation considers all variations of a letter equal. You have to use a binary collation (utf8_bin
) or a collation based on a national standard (such as utf8_czech_ci
) if you want to treat S and Š as distinct letters.
utf8_general_ci排序规则认为字母的所有变体都相等。如果要将S和Š视为不同的字母,则必须使用二进制排序规则(utf8_bin)或基于国家标准的排序规则(例如utf8_czech_ci)。
#1
1
The utf8_general_ci
collation considers all variations of a letter equal. You have to use a binary collation (utf8_bin
) or a collation based on a national standard (such as utf8_czech_ci
) if you want to treat S and Š as distinct letters.
utf8_general_ci排序规则认为字母的所有变体都相等。如果要将S和Š视为不同的字母,则必须使用二进制排序规则(utf8_bin)或基于国家标准的排序规则(例如utf8_czech_ci)。