<?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 : ORDER BY numbers</title>
	<atom:link href="http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/</link>
	<description>Web Development Resources</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:42:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Narong</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-8801</link>
		<dc:creator>Narong</dc:creator>
		<pubDate>Sat, 10 Dec 2011 02:46:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-8801</guid>
		<description>Thanks for the tutorial!</description>
		<content:encoded><![CDATA[<p>Thanks for the tutorial!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oslo Hudlege</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-8762</link>
		<dc:creator>Oslo Hudlege</dc:creator>
		<pubDate>Wed, 16 Nov 2011 13:42:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-8762</guid>
		<description>thank you so much for solving my issue...</description>
		<content:encoded><![CDATA[<p>thank you so much for solving my issue&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: muhammed sekertekin</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-8728</link>
		<dc:creator>muhammed sekertekin</dc:creator>
		<pubDate>Mon, 17 Oct 2011 10:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-8728</guid>
		<description>Thank you very much this helps me a lot. i almost give up with mysql query until i saw this article ....muhammed sekertekin</description>
		<content:encoded><![CDATA[<p>Thank you very much this helps me a lot. i almost give up with mysql query until i saw this article &#8230;.muhammed sekertekin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zno</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-8645</link>
		<dc:creator>Zno</dc:creator>
		<pubDate>Mon, 05 Sep 2011 03:41:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-8645</guid>
		<description>hi all
my problem is similar to fictus but unfortunately the &quot;first&quot; number can be 1,2 or 3 digit(s).
how can i sort in right way?

for example:
1mm N52 NEODYM
10mm N52 NEODYM
100mm N52 NEODYM
2mm N52 NEODYM
3mm N52 NEODYM

what i need:
1mm N52 NEODYM
2mm N52 NEODYM
3mm N52 NEODYM
10mm N52 NEODYM
100mm N52 NEODYM</description>
		<content:encoded><![CDATA[<p>hi all<br />
my problem is similar to fictus but unfortunately the &#8220;first&#8221; number can be 1,2 or 3 digit(s).<br />
how can i sort in right way?</p>
<p>for example:<br />
1mm N52 NEODYM<br />
10mm N52 NEODYM<br />
100mm N52 NEODYM<br />
2mm N52 NEODYM<br />
3mm N52 NEODYM</p>
<p>what i need:<br />
1mm N52 NEODYM<br />
2mm N52 NEODYM<br />
3mm N52 NEODYM<br />
10mm N52 NEODYM<br />
100mm N52 NEODYM</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nuntius</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-8638</link>
		<dc:creator>nuntius</dc:creator>
		<pubDate>Wed, 31 Aug 2011 19:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-8638</guid>
		<description>Thanks for the example. 

Another way is to use the +0 option (although I understand it is a bit slower), but it sometimes works when ABS() wont. I had an problem where we had been numbering our issues as volume.issue_number. 

For example. 1.1 is the first issue of the first volume and 1.10 is the tenth issue of the first volume. The proper way would have been to get them to use .01, but let&#039;s face it... we don&#039;t always thing that way in advance, so I was in a bind! I tried ABS and it didn&#039;t work in this situation for some reason, so I turned to +0.

What I discovered after a lot of research is that you can do something fancy by using the +0 option combined with SUBSTRING_INDEX and ORDER BY to split a field during the query. 

SELECT DISTINCT issue FROM tbl_pages 
WHERE isActive=1
ORDER BY 
(SUBSTRING_INDEX(issue, &#039;.&#039;, 1)+0),
(SUBSTRING_INDEX(issue, &#039;.&#039;, -1)+0)

This query first orders the issues numerically by the volume number in the field and then orders the issue numerically by issue number. SUBSTRING_INDEX is recognizing the period as a delimiter and 
breaking up the column, in order to sort correctly.

Hope this helps someone.</description>
		<content:encoded><![CDATA[<p>Thanks for the example. </p>
<p>Another way is to use the +0 option (although I understand it is a bit slower), but it sometimes works when ABS() wont. I had an problem where we had been numbering our issues as volume.issue_number. </p>
<p>For example. 1.1 is the first issue of the first volume and 1.10 is the tenth issue of the first volume. The proper way would have been to get them to use .01, but let&#8217;s face it&#8230; we don&#8217;t always thing that way in advance, so I was in a bind! I tried ABS and it didn&#8217;t work in this situation for some reason, so I turned to +0.</p>
<p>What I discovered after a lot of research is that you can do something fancy by using the +0 option combined with SUBSTRING_INDEX and ORDER BY to split a field during the query. </p>
<p>SELECT DISTINCT issue FROM tbl_pages<br />
WHERE isActive=1<br />
ORDER BY<br />
(SUBSTRING_INDEX(issue, &#8216;.&#8217;, 1)+0),<br />
(SUBSTRING_INDEX(issue, &#8216;.&#8217;, -1)+0)</p>
<p>This query first orders the issues numerically by the volume number in the field and then orders the issue numerically by issue number. SUBSTRING_INDEX is recognizing the period as a delimiter and<br />
breaking up the column, in order to sort correctly.</p>
<p>Hope this helps someone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bobby</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-7572</link>
		<dc:creator>bobby</dc:creator>
		<pubDate>Thu, 16 Jun 2011 23:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-7572</guid>
		<description>thx for code</description>
		<content:encoded><![CDATA[<p>thx for code</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruno Thomasi</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-7567</link>
		<dc:creator>Bruno Thomasi</dc:creator>
		<pubDate>Fri, 10 Jun 2011 13:28:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-7567</guid>
		<description>thx man from Brasil!</description>
		<content:encoded><![CDATA[<p>thx man from Brasil!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: biotechnology student</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-7447</link>
		<dc:creator>biotechnology student</dc:creator>
		<pubDate>Mon, 28 Feb 2011 08:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-7447</guid>
		<description>pls tell me how to concatinate two number fields in mysql.</description>
		<content:encoded><![CDATA[<p>pls tell me how to concatinate two number fields in mysql.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos Granier-Phelps</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-7405</link>
		<dc:creator>Carlos Granier-Phelps</dc:creator>
		<pubDate>Tue, 08 Feb 2011 17:43:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-7405</guid>
		<description>Thanks! Saved me a ton of research, trial and error - trying to sort numerically on a longtext field. Worked like a charm.</description>
		<content:encoded><![CDATA[<p>Thanks! Saved me a ton of research, trial and error &#8211; trying to sort numerically on a longtext field. Worked like a charm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fictus</title>
		<link>http://www.lost-in-code.com/programming/mysql/mysql-order-by-numbers/comment-page-1/#comment-7391</link>
		<dc:creator>fictus</dc:creator>
		<pubDate>Tue, 01 Feb 2011 16:04:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.lost-in-code.com/?p=250#comment-7391</guid>
		<description>Wow! This even works on text fields that include numbers and text characters together!

For example, my field was able to sort numbers even when I had values as such:

230-Medium
440-High
110-Low

Thanks for the example!</description>
		<content:encoded><![CDATA[<p>Wow! This even works on text fields that include numbers and text characters together!</p>
<p>For example, my field was able to sort numbers even when I had values as such:</p>
<p>230-Medium<br />
440-High<br />
110-Low</p>
<p>Thanks for the example!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

