<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.joaomorais.com &#187; Bug</title>
	<atom:link href="http://blog.joaomorais.com/tag/bug/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.joaomorais.com</link>
	<description>Blog about software development, personal projects and development tools.</description>
	<lastBuildDate>Mon, 10 Apr 2017 02:26:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>MySQL bug related with natural number order fix</title>
		<link>http://blog.joaomorais.com/mysql-bug-related-with-natural-number-order-fix/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-bug-related-with-natural-number-order-fix</link>
		<comments>http://blog.joaomorais.com/mysql-bug-related-with-natural-number-order-fix/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 11:11:21 +0000</pubDate>
		<dc:creator>João Morais</dc:creator>
				<category><![CDATA[Papers]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Fix]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Number]]></category>
		<category><![CDATA[Order]]></category>

		<guid isPermaLink="false">http://solidlocker.webhs.org/wordpress/?p=161</guid>
		<description><![CDATA[It seems that this is a known bug but I only noticed it yesterday. Imagine you have a field named price and it&#8217;s type is VARCHAR (it doesn&#8217;t matter why it&#8217;s not INT or FLOAT) and you want to use ORDER BY clause so you can list table rows ordered by price value. It won&#8217;t [...]]]></description>
				<content:encoded><![CDATA[<p>It seems that this is a known bug but I only noticed it yesterday.</p>
<p>Imagine you have a field named price and it&#8217;s type is VARCHAR (it doesn&#8217;t matter why it&#8217;s not INT or FLOAT) and you want to use ORDER BY clause so you can list table rows ordered by price value.</p>
<p>It won&#8217;t work, since the prices will be listed alphabetically, you may read here how to fix this issue.</p>
<p><span id="more-161"></span>If you have a table labeled products, a field labeled price (typed as VARCHAR) and the following values: 1, 2, 3, 7, 8, 53, 47, 32, 99 and 327.</p>
<p>And you perform a query similar to the one below:</p>
<pre class="brush:sql">SELECT price FROM products ORDER BY price;</pre>
<p>The result will be:</p>
<pre class="brush:plain">1, 2, 3, 32, 327,47, 53, 7, 8, 99</pre>
<p>As you can see the product prices are ordered alphabetically to fix this you should add + 0 to the query (see example below):</p>
<pre class="brush:sql">SELECT price FROM products ORDER BY price + 0;</pre>
<p>The result will be:</p>
<pre class="brush:plain">1, 2, 3, 7, 8, 32, 47, 53, 99, 327</pre>
<p>Problem solved, now your rows will be sorted by price correctly.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.joaomorais.com/mysql-bug-related-with-natural-number-order-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
