<?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: Finding the smallest or largest value across multiple columns in MySQL</title>
	<atom:link href="http://dancingpenguinsoflight.com/2009/03/finding-the-smallest-or-largest-value-across-multiple-columns-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://dancingpenguinsoflight.com/2009/03/finding-the-smallest-or-largest-value-across-multiple-columns-in-mysql/</link>
	<description></description>
	<lastBuildDate>Sat, 19 May 2012 07:40:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Dieter Köhler</title>
		<link>http://dancingpenguinsoflight.com/2009/03/finding-the-smallest-or-largest-value-across-multiple-columns-in-mysql/comment-page-1/#comment-84386</link>
		<dc:creator>Dieter Köhler</dc:creator>
		<pubDate>Wed, 09 May 2012 16:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=716#comment-84386</guid>
		<description>The code can be improved to take care for the case when all dates are NULL:
&lt;code&gt;
SELECT id, date1, date2, date3, date4,
nullif(
least(
ifnull(date1, &#039;9999-99-99&#039;),
ifnull(date2, &#039;9999-99-99&#039;),
ifnull(date3, &#039;9999-99-99&#039;),
ifnull(date4, &#039;9999-99-99&#039;)
), 
&#039;9999-99-99&#039;) AS first_date
FROM my_db.my_table
GROUP BY id;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>The code can be improved to take care for the case when all dates are NULL:</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT id, date1, date2, date3, date4,<br />
nullif(<br />
least(<br />
ifnull(date1, '9999-99-99'),<br />
ifnull(date2, '9999-99-99'),<br />
ifnull(date3, '9999-99-99'),<br />
ifnull(date4, '9999-99-99')<br />
), <br />
'9999-99-99') AS first_date<br />
FROM my_db.my_table<br />
GROUP BY id;</div></td></tr></tbody></table></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charan Singh</title>
		<link>http://dancingpenguinsoflight.com/2009/03/finding-the-smallest-or-largest-value-across-multiple-columns-in-mysql/comment-page-1/#comment-68898</link>
		<dc:creator>Charan Singh</dc:creator>
		<pubDate>Tue, 31 Jan 2012 15:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=716#comment-68898</guid>
		<description>Hello !
I&#039;m trying to compare 5 columns for the highest and lowest values in these with some cells/rows as null value; Following above example when I am trying to run the query it doesn&#039;t bring least value in the  &quot;Resultvalue&quot; column, it brings NULL cell/row with no Value in these, where ever there is null in the col1 to col5 and only brings the least correct value results if no col is null/ where null doesnt get substituted with 999 value as per this query. Please guide

Use Db;
Create table Test  As 
SELECT *,
least(ifnull(col1,&#039;999&#039;),
ifnull(col2, &#039;999&#039;),
ifnull(col3, &#039;999&#039;),
ifnull(col4, &#039;999&#039;),
ifnull(col5, &#039;999&#039;)
) AS Resultvalue,
From table Db.Test
Group by Id;</description>
		<content:encoded><![CDATA[<p>Hello !<br />
I&#8217;m trying to compare 5 columns for the highest and lowest values in these with some cells/rows as null value; Following above example when I am trying to run the query it doesn&#8217;t bring least value in the  &#8220;Resultvalue&#8221; column, it brings NULL cell/row with no Value in these, where ever there is null in the col1 to col5 and only brings the least correct value results if no col is null/ where null doesnt get substituted with 999 value as per this query. Please guide</p>
<p>Use Db;<br />
Create table Test  As<br />
SELECT *,<br />
least(ifnull(col1,&#8217;999&#8242;),<br />
ifnull(col2, &#8217;999&#8242;),<br />
ifnull(col3, &#8217;999&#8242;),<br />
ifnull(col4, &#8217;999&#8242;),<br />
ifnull(col5, &#8217;999&#8242;)<br />
) AS Resultvalue,<br />
From table Db.Test<br />
Group by Id;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Atea</title>
		<link>http://dancingpenguinsoflight.com/2009/03/finding-the-smallest-or-largest-value-across-multiple-columns-in-mysql/comment-page-1/#comment-14933</link>
		<dc:creator>Atea</dc:creator>
		<pubDate>Mon, 05 Apr 2010 17:12:21 +0000</pubDate>
		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=716#comment-14933</guid>
		<description>Thanks! I was looking for hours for this!

My solution for two columns with decimals:

SELECT LEAST(price_month_regular, ifnull(price_month_action, 9999)) AS least FROM `cp_contracts` ORDER BY least</description>
		<content:encoded><![CDATA[<p>Thanks! I was looking for hours for this!</p>
<p>My solution for two columns with decimals:</p>
<p>SELECT LEAST(price_month_regular, ifnull(price_month_action, 9999)) AS least FROM `cp_contracts` ORDER BY least</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Don McArthur</title>
		<link>http://dancingpenguinsoflight.com/2009/03/finding-the-smallest-or-largest-value-across-multiple-columns-in-mysql/comment-page-1/#comment-1055</link>
		<dc:creator>Don McArthur</dc:creator>
		<pubDate>Sat, 21 Mar 2009 13:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://dancingpenguinsoflight.com/?p=716#comment-1055</guid>
		<description>Most implementations of SQL don&#039;t allow the mixing of grouped and ungrouped columns in the SELECT clause. MySQL does, but the row selected for display from the ungrouped column is essentially randomly chosen. The groupwise max solution is a means of overcoming this.

http://jan.kneschke.de/projects/mysql/groupwise-max/</description>
		<content:encoded><![CDATA[<p>Most implementations of SQL don&#8217;t allow the mixing of grouped and ungrouped columns in the SELECT clause. MySQL does, but the row selected for display from the ungrouped column is essentially randomly chosen. The groupwise max solution is a means of overcoming this.</p>
<p><a href="http://jan.kneschke.de/projects/mysql/groupwise-max/" rel="nofollow">http://jan.kneschke.de/projects/mysql/groupwise-max/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

