<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

      <title>Comments on: How to get mySQL to ignore "A, An, &amp; The" when presenting alphabetized book titles</title>
      <link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles/</link>
      <description>Comments on Ask MetaFilter post How to get mySQL to ignore "A, An, &amp; The" when presenting alphabetized book titles</description>
	  	  <pubDate>Tue, 05 Dec 2006 09:02:37 -0800</pubDate>
      <lastBuildDate>Tue, 05 Dec 2006 09:02:37 -0800</lastBuildDate>
      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>

<item>
  	<title>Question: How to get mySQL to ignore &quot;A, An, &amp;amp; The&quot; when presenting alphabetized book titles</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles</link>	
  	<description>mySQLfilter: How can I ignore &quot;A, An, &amp;amp; The&quot; at the beginning of book titles when sorting results alphabetically by title? &lt;br /&gt;&lt;br /&gt; I have a database of several hundred book titles and I&apos;d like to be able to list them alphabetically, but ignore any articles that may be at the front of title.&lt;br&gt;
&lt;br&gt;
For example, consider the following 3 titles as they appear in the db:&lt;br&gt;
&lt;br&gt;
&quot;A Summer&apos;s Day&quot;&lt;br&gt;
&quot;Beach Fun&quot;&lt;br&gt;
&quot;Zebras Are Neat&quot;&lt;br&gt;
&lt;br&gt;
I&apos;d like them to appear, in order, as:&lt;br&gt;
&lt;br&gt;
&quot;Beach Fun&quot;&lt;br&gt;
&quot;A Summer&apos;s Day&quot; (See? Ignoring the first article &quot;A&quot; and alphabetizing on the &quot;S&quot;)&lt;br&gt;
&quot;Zebras Are Neat&quot;&lt;br&gt;
&lt;br&gt;
I&apos;m assuming that there&apos;s some sort of conditional code I could use in mySQL to make this easier.&lt;br&gt;
&lt;br&gt;
I also have (some) PHP skills, so writing a helper function or two isn&apos;t out of the question.</description>
  	<guid isPermaLink="false">post:ask.metafilter.com,2008:site.52434</guid>
  	<pubDate>Tue, 05 Dec 2006 08:36:40 -0800</pubDate>
  	<dc:creator>Wild_Eep</dc:creator>
	
	<category>mysql</category>
	
	<category>sorting</category>
	
	<category>alphabetical</category>
	
	<category>database</category>
	
	<category>sql</category>
	
	<category>books</category>
	
	<category>title</category>
	
	<category>titles</category>
	
	<category>book</category>
	
</item>
<item>
  	<title>By: cillit bang</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791470</link>	
  	<description>ORDER BY IF(LEFT(title,2)=&amp;quot;A &amp;quot;,SUBSTRING(title FROM 3),IF(LEFT(title,3)=&amp;quot;An &amp;quot;,SUBSTRING(title FROM 4),IF(LEFT(title,4)=&amp;quot;The &amp;quot;,SUBSTRING(title FROM 5),title)));&lt;br&gt;
&lt;br&gt;
Or something equally horrible. I&apos;d create an extra column with this stored, however.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791470</guid>
  	<pubDate>Tue, 05 Dec 2006 09:02:37 -0800</pubDate>
  	<dc:creator>cillit bang</dc:creator>
</item>
<item>
  	<title>By: mkultra</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791478</link>	
  	<description>Doing this real-time within your SELECT query is going to be very expensive. I&apos;d add another field to your titles table called &amp;quot;SortTitle&amp;quot;, and do your logic in PHP before insert:&lt;br&gt;
&lt;br&gt;
if(substr($title, 0, 2) == &amp;quot;A &amp;quot;)&lt;br&gt;
{&lt;br&gt;
$title = substr($title,2,(strlen($title)-2))&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
... and so on. I&apos;m sure there&apos;s some tighter function to strip out a series of possible starting articles, but that should do the trick.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791478</guid>
  	<pubDate>Tue, 05 Dec 2006 09:10:19 -0800</pubDate>
  	<dc:creator>mkultra</dc:creator>
</item>
<item>
  	<title>By: nicwolff</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791479</link>	
  	<description>I don&apos;t use MySQL but this should work, same basic concept as cillit&apos;s:&lt;br&gt;
&lt;br&gt;
SELECT book_id, book_name FROM books ORDER BY TRIM( LEADING &apos;a &apos; FROM TRIM( LEADING &apos;an &apos; FROM TRIM( LEADING &apos;the &apos; FROM LOWER( book_name ) ) ) );</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791479</guid>
  	<pubDate>Tue, 05 Dec 2006 09:10:29 -0800</pubDate>
  	<dc:creator>nicwolff</dc:creator>
</item>
<item>
  	<title>By: waldo</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791531</link>	
  	<description>I have solved this in the past by writing a quick PHP script to crawl through the records and rotate &amp;quot;A,&amp;quot; &amp;quot;An&amp;quot; and &amp;quot;The&amp;quot; to the end of the name like such:&lt;br&gt;
&lt;br&gt;
New Day at Midnight, A&lt;br&gt;
&lt;br&gt;
Then I query normally.  And I use a little function (I call it it &amp;quot;pivot&amp;quot;) to check each title for &amp;quot;, A&amp;quot; or &amp;quot;, An&amp;quot; or &amp;quot;, The&amp;quot; at the end and, if found, pivot that suffix to the beginning and strip out the comma.  It&apos;s significantly easier then doing it in MySQL.&lt;br&gt;
&lt;br&gt;
From there on out, of course, you&apos;ll want to insert the data with the prefixes rotated around to become suffixes.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791531</guid>
  	<pubDate>Tue, 05 Dec 2006 10:11:28 -0800</pubDate>
  	<dc:creator>waldo</dc:creator>
</item>
<item>
  	<title>By: RustyBrooks</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791533</link>	
  	<description>In in-place-select examples are going to screw up if the title starts with a but not the article a, like &amp;quot;Albino Alligators&amp;quot;.  It would also mess up things like &amp;quot;thesaurus&amp;quot; because it starts with &amp;quot;the&amp;quot;.&lt;br&gt;
&lt;br&gt;
I&apos;d advocate creating a new column with the &amp;quot;sort title&amp;quot; and making a good routine to populate this column.  If you have an existing database you&apos;ll have to step through all the rows and populate this column.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791533</guid>
  	<pubDate>Tue, 05 Dec 2006 10:14:50 -0800</pubDate>
  	<dc:creator>RustyBrooks</dc:creator>
</item>
<item>
  	<title>By: cmiller</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791595</link>	
  	<description>Seconding the &amp;quot;sort_title&amp;quot; column idea.  You should do it at insertion time, too.  Beware foreign languages.&lt;br&gt;
&lt;br&gt;
Boot, Das&lt;br&gt;
Cars&lt;br&gt;
Fabuleux destin d&apos;Am&#xe9;lie Poulain, Le&lt;br&gt;
Hunt for Red October, The</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791595</guid>
  	<pubDate>Tue, 05 Dec 2006 11:13:24 -0800</pubDate>
  	<dc:creator>cmiller</dc:creator>
</item>
<item>
  	<title>By: cmicali</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791598</link>	
  	<description>Why not clean the data (articles at the end of the titles) before it gets into the database?  You could clean the data that is already in the database once now and then just ensure new data going in has been cleaned before insertion.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791598</guid>
  	<pubDate>Tue, 05 Dec 2006 11:18:56 -0800</pubDate>
  	<dc:creator>cmicali</dc:creator>
</item>
<item>
  	<title>By: nicwolff</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791733</link>	
  	<description>Jeez, guys, he said how he&apos;d like them to appear, and it&apos;s not with the articles moved to the end of the names - he just wants to sort them that way. &lt;br&gt;
&lt;br&gt;
It&apos;s generally better to operate on data in its canonical form if possible, rather than introduce integrity issues by storing the same information in multiple formats.&lt;br&gt;
&lt;br&gt;
Speed is hardly going to be an issue for MySQL running a simple text operation on a couple of hundred records.&lt;br&gt;
&lt;br&gt;
And, RustyBrooks, see the spaces in &apos;a &apos;, &apos;an &apos;, &apos;the &apos; in cillit&apos;s and my SQL examples? They&apos;ll work fine.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791733</guid>
  	<pubDate>Tue, 05 Dec 2006 12:50:58 -0800</pubDate>
  	<dc:creator>nicwolff</dc:creator>
</item>
<item>
  	<title>By: kamelhoecker</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#791868</link>	
  	<description>i&apos;ve stored my data in the format in SQL sort format, and then make it pretty when I need to output it, as waldo suggests. Works fine, and you don&apos;t have to worry about keeping two columns (e.g. title and sort_title) updated.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-791868</guid>
  	<pubDate>Tue, 05 Dec 2006 14:48:50 -0800</pubDate>
  	<dc:creator>kamelhoecker</dc:creator>
</item>
<item>
  	<title>By: AmbroseChapel</title>
  	<link>http://ask.metafilter.com/52434/How-to-get-mySQL-to-ignore-A-An-amp-The-when-presenting-alphabetized-book-titles#792001</link>	
  	<description>I vote for an &amp;quot;article&amp;quot; column which holds the &amp;quot;a&amp;quot;, &amp;quot;an&amp;quot; and &amp;quot;the&amp;quot;. That&apos;s how I&apos;ve always done it.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.52434-792001</guid>
  	<pubDate>Tue, 05 Dec 2006 17:04:13 -0800</pubDate>
  	<dc:creator>AmbroseChapel</dc:creator>
</item>

    </channel>
</rss>
