This comes up a lot, and I can see it's come up on StackOverflow for XSLT, Ruby and Drupal but I don't see it specifically for SQL.
So the question is, how do you sort titles correctly when they begin with "The", "A", or "An"?
One way is simply to TRIM() those strings:
ORDER BY TRIM(
LEADING 'a ' FROM
TRIM(
LEADING 'an ' FROM
TRIM(
LEADING 'the ' FROM LOWER( title )
)
)
)
which was suggested on AskMeFi a while back (does it need that LOWER()
function?).
I know I've also seen some kind of Case/Switch implementation of this but it's a little hard to Google for.
Obviously there are a number of possible solutions. What would be good is SQL gurus weighing in on which have performance implications.