Reputation: 9539
Question: Where can I find the precedence of characters when sorting in MySQL, PHP, or just in general on Linux and Windows OS?
For example, everybody knows that a comes before b when performing an ascending sort on a string in MySQL. But what about other characters? Does the dollar-sign $ come before asterisk * ? Does a space come before an exclamation-mark? etc...
What dictates the sort order? Does it use underlying ascii / UTF-8 values? Is it different for different technologies?
Technologies to consider:
Upvotes: 5
Views: 1002
Reputation: 4560
Upvotes: 1
Reputation: 7597
It gets even more interesting when considering other languages.
Ä and ö are letters with accents in Dutch and German, but 'real' letters in the Swedish alphabet (after Z, not between A and B/O and L respectively).
Upvotes: 1
Reputation: 6947
In database terms, this is called the collation sequence, and most character sets have a default. If you are using unicode, you might look here: http://www.unicode.org/reports/tr10/tr10-24.html
Upvotes: 1
Reputation: 36476
Characters are represented as mappings from an unsigned integer type to a particular glyph. The particular mapping is defined by the character set.
Thus when you compare characters, you are really comparing the integer that represents the character in a particular charset.
e.g. Java compares String
s based on their unicode representations. Source
Upvotes: 1