Unexpected results from SELECT with ORDER BY

#1

Given a set of records with a string field “name” that contains, for example:

Bob
Sam
[Zach]
Jane
[Mike]

Using ORDER BY name will return:

[Mike]
[Zach]
Bob
Jane
Sam

I would have expected this (items with square brackets at the end):

Bob
Jane
Sam
[Mike]
[Zach]

I wonder if this is the effect of case-insensitivity on the ORDER BY, but is it in fact case-insensitive? If so, how/where is that set? If not, what would cause this sort order (where the items with square brackets are first)?

#2

Hi @eric24

The sorting is based on basic Java string sorting, there is no magic behind it.
I guess it’s just the way Java sorts strings

Thanks

Luigi

#3

@luigidellaquila: Hmm. Can you point me to the code that does this? Is it a simple String#compareTo() or String#compareToIgnoreCase() or are you using the Collator class and/or a localized comparison? Based on what I’m seeing, it’s probably the latter, since the output of ORDER BY does not appear to be case-sensitive.