About Sort Order
When you sort collections, you must understand these concepts:
- Some fields that appear to be numeric (for example, Account) might actually be character-based and would use text-character sort order.
- Character-based fields use
text-character sorting. For example, if you attempt an ascending sort by
account number, the accounts might be sorted like this:
(blank field)
#222
222
2220
@201
XL-64
xl-64
In text-character (ascending) order, these rules exist:
- Character strings are generally sorted from left to right. That is, the first character (furthest left) is evaluated, then the second, and so on.
- A blank field comes before any other character. Thus, any blank fields always display first.
- Special characters might come before numerals, between numerals and letters, or after letters. Thus, #222 comes before 222, but @201 comes after 222.
- Numerals display in correct numeric order, regardless of size.
- Numerals display before alphabetic characters.
- Upper-case characters display before lower-case characters. Thus, XL-64 comes before xl-64.
- Unicode strings typically are compared using a "word sort" technique, where all punctuation marks and other non-alphanumeric characters, except for the hyphen and the apostrophe, come before any alphanumeric character. The hyphen and the apostrophe are treated differently than the other non-alphanumeric symbols, in order to ensure that words such as coop and co-op stay together within a sorted list.
Related topics