<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MySQL Natural Sort Order By on Non-Numeric Field Type</title>
	<atom:link href="http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Wed, 08 Feb 2012 15:26:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Steve</title>
		<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/comment-page-1/#comment-17073</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 01 Dec 2011 16:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1408#comment-17073</guid>
		<description>If the length of the alphabetic portion of the string is constant, like it was in my case, you can use something like this:

        ORDER BY SUBSTR(name FROM 1 FOR 6), CAST(SUBSTR(name FROM 7) AS UNSIGNED), SUBSTR(machine.name FROM 7)

Notice that the ordering will only be different from a straight alphabetic ordering when there are numeric digits starting at character 7.
So, a list like [&#039;string123&#039;, &#039;string5&#039;, &#039;string20&#039;] which would normally be sorted as [&#039;string123&#039;, &#039;string20&#039;, &#039;string5&#039;], will instead be sorted as [&#039;string5&#039;, &#039;string20&#039;, &#039;string123&#039;].</description>
		<content:encoded><![CDATA[<p>If the length of the alphabetic portion of the string is constant, like it was in my case, you can use something like this:</p>
<p>        ORDER BY SUBSTR(name FROM 1 FOR 6), CAST(SUBSTR(name FROM 7) AS UNSIGNED), SUBSTR(machine.name FROM 7)</p>
<p>Notice that the ordering will only be different from a straight alphabetic ordering when there are numeric digits starting at character 7.<br />
So, a list like ['string123', 'string5', 'string20'] which would normally be sorted as ['string123', 'string20', 'string5'], will instead be sorted as ['string5', 'string20', 'string123'].</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edwin Sandoval</title>
		<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/comment-page-1/#comment-2132</link>
		<dc:creator>Edwin Sandoval</dc:creator>
		<pubDate>Tue, 07 Sep 2010 18:39:08 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1408#comment-2132</guid>
		<description>Good Mysql Tip, thank very much : )</description>
		<content:encoded><![CDATA[<p>Good Mysql Tip, thank very much : )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gaarai</title>
		<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/comment-page-1/#comment-2053</link>
		<dc:creator>gaarai</dc:creator>
		<pubDate>Thu, 19 Aug 2010 14:16:56 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1408#comment-2053</guid>
		<description>Yes. I&#039;ve since found this out. My &quot;trick&quot; worked for the initial data sets that I needed it for, but it obviously doesn&#039;t work as expected for all (most?) datasets.

For more than a year now I have revisited this problem off and on and have yet to find a better (read &quot;actual&quot;) solution to this need without using code to reorder the results.</description>
		<content:encoded><![CDATA[<p>Yes. I&#8217;ve since found this out. My &#8220;trick&#8221; worked for the initial data sets that I needed it for, but it obviously doesn&#8217;t work as expected for all (most?) datasets.</p>
<p>For more than a year now I have revisited this problem off and on and have yet to find a better (read &#8220;actual&#8221;) solution to this need without using code to reorder the results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eli</title>
		<link>http://chrisjean.com/2009/04/19/mysql-natural-sort-order-by-on-non-numeric-field-type/comment-page-1/#comment-2045</link>
		<dc:creator>Eli</dc:creator>
		<pubDate>Fri, 13 Aug 2010 19:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://gaarai.com/?p=1408#comment-2045</guid>
		<description>this method only works for numeric, does not work for strings with numeric values

does not work:
a10,a11,a120,a21,a3,aa1

also does not work:
10a,10c,10b

also I believe a1 comes first in your list not last, since a1 casts to int 0</description>
		<content:encoded><![CDATA[<p>this method only works for numeric, does not work for strings with numeric values</p>
<p>does not work:<br />
a10,a11,a120,a21,a3,aa1</p>
<p>also does not work:<br />
10a,10c,10b</p>
<p>also I believe a1 comes first in your list not last, since a1 casts to int 0</p>
]]></content:encoded>
	</item>
</channel>
</rss>

