title: How to sort in SQL, ignoring articles ('the", "a', "an" etc)
body: <p>This comes up a lot, and I can see it's come up on StackOverflow for <a href="https://stackoverflow.com/questions/2848641/ignoring-a-and-the-when-sorting-with-xslt">XSLT</a>, <a href="https://stackoverflow.com/questions/1402915/sort-an-array-in-ruby-ignoring-articles-the-a-an">Ruby</a> and <a href="https://stackoverflow.com/questions/3189092/ignore-the-when-sorting-a-view-in-drupal">Drupal</a> but I don't see it specifically for SQL.</p>
  <p>So the question is, how do you sort titles correctly when they begin with &quot;The&quot;, &quot;A&quot;, or &quot;An&quot;?</p>
  <p>One way is simply to TRIM() those strings:</p>
  <pre><code>ORDER BY TRIM( 
    LEADING 'a ' FROM 
    TRIM( 
      LEADING 'an ' FROM 
      TRIM( 
        LEADING 'the ' FROM LOWER( title ) 
        ) 
      ) 
    )
  </code></pre>
  <p>which was <a href="http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-and-The-when-presenting-alphabetized-book-titles" rel="noreferrer">suggested on AskMeFi</a> a while back (does it need that <code>LOWER()</code> function?).</p>
  <p>I know I've also seen some kind of Case/Switch implementation of this but it's a little hard to Google for.</p>
  <p>Obviously there are a number of possible solutions. What would be good is SQL gurus weighing in on which have performance implications.</p>