<?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"
	>
<channel>
	<title>Comments on: How to avoid many-to-one problems in SQL</title>
	<atom:link href="http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/</link>
	<description>Stay curious!</description>
	<pubDate>Tue, 07 Oct 2008 03:02:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Re: bookmarks and keywords &#124; Bla.es</title>
		<link>http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/#comment-13429</link>
		<dc:creator>Re: bookmarks and keywords &#124; Bla.es</dc:creator>
		<pubDate>Mon, 01 Oct 2007 09:58:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=104#comment-13429</guid>
		<description>[...] www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/ [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/" rel="nofollow" >http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/#comment-3006</link>
		<dc:creator>Xaprb</dc:creator>
		<pubDate>Sun, 07 Jan 2007 15:02:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=104#comment-3006</guid>
		<description>&lt;p&gt;I probably answered your question in one of my two posts on duplicate rows.  Here is the first: &lt;a href="/blog/2006/10/09/how-to-find-duplicate-rows-with-sql/" rel="nofollow"&gt;how to find duplicate rows&lt;/a&gt;.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>I probably answered your question in one of my two posts on duplicate rows.  Here is the first: <a href="/blog/2006/10/09/how-to-find-duplicate-rows-with-sql/" rel="nofollow">how to find duplicate rows</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TEJAS</title>
		<link>http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/#comment-2997</link>
		<dc:creator>TEJAS</dc:creator>
		<pubDate>Sat, 06 Jan 2007 06:19:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=104#comment-2997</guid>
		<description>&lt;p&gt;Hi, I really loved the way you've explained SQL.  My Query is
   
How to select (and then delete) a duplicate entry in a table
where some of the columns of that specific rows contains nothing or NULL ?&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hi, I really loved the way you&#8217;ve explained SQL.  My Query is</p>
<p>How to select (and then delete) a duplicate entry in a table<br />
where some of the columns of that specific rows contains nothing or NULL ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/#comment-1012</link>
		<dc:creator>Xaprb</dc:creator>
		<pubDate>Mon, 03 Jul 2006 15:22:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=104#comment-1012</guid>
		<description>&lt;p&gt;Anton, that's exactly right.  It's an optimization to avoid unnecessary columns in the GROUP BY clause.  You and I know that column is not needed, because we know the data in the table.&lt;/p&gt;

&lt;p&gt;But from a theoretical point of view, it doesn't have to be so.  It's just a coincidence that one column's values stay the same over the entire range of another's.  And even though as you point out, the index structure forces it to be that way, it doesn't change the formal mathematical reality.&lt;/p&gt;

&lt;p&gt;SQL GROUP BY statements are either valid or not.  Validation does not take indexing into consideration.  It does not examine the table structure or the data in the table to decide whether a grouping is valid.  The reality is, a grouping produces one row per group.  If a query selects a column in a grouped query, it must either be in the GROUP BY clause or in an aggregate function.  Those are the only two ways a query can know for sure it will find a single value to place into that column in the result.&lt;/p&gt;

&lt;p&gt;MySQL's method is to choose an undeterminate one of the values.  If I, a human, know there's only one possibility, OK, I am free to make that decision.  But the query cannot know that.  That's why such queries are nonsense from a formal point of view.&lt;/p&gt;

&lt;p&gt;That said -- I work with the tools I have.  If I need to make my queries more efficient, I'll use my tools to achieve my goal, whether it follows standards or not.  What's really important in these queries is to understand why the query, in and of itself, is not guaranteed to be deterministic.  Then I can make educated decisions about whether the query, with a given set of data, will give the results I want.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Anton, that&#8217;s exactly right.  It&#8217;s an optimization to avoid unnecessary columns in the GROUP BY clause.  You and I know that column is not needed, because we know the data in the table.</p>
<p>But from a theoretical point of view, it doesn&#8217;t have to be so.  It&#8217;s just a coincidence that one column&#8217;s values stay the same over the entire range of another&#8217;s.  And even though as you point out, the index structure forces it to be that way, it doesn&#8217;t change the formal mathematical reality.</p>
<p>SQL GROUP BY statements are either valid or not.  Validation does not take indexing into consideration.  It does not examine the table structure or the data in the table to decide whether a grouping is valid.  The reality is, a grouping produces one row per group.  If a query selects a column in a grouped query, it must either be in the GROUP BY clause or in an aggregate function.  Those are the only two ways a query can know for sure it will find a single value to place into that column in the result.</p>
<p>MySQL&#8217;s method is to choose an undeterminate one of the values.  If I, a human, know there&#8217;s only one possibility, OK, I am free to make that decision.  But the query cannot know that.  That&#8217;s why such queries are nonsense from a formal point of view.</p>
<p>That said &#8212; I work with the tools I have.  If I need to make my queries more efficient, I&#8217;ll use my tools to achieve my goal, whether it follows standards or not.  What&#8217;s really important in these queries is to understand why the query, in and of itself, is not guaranteed to be deterministic.  Then I can make educated decisions about whether the query, with a given set of data, will give the results I want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anton Eccles</title>
		<link>http://www.xaprb.com/blog/2006/03/11/many-to-one-problems-in-sql/#comment-1011</link>
		<dc:creator>Anton Eccles</dc:creator>
		<pubDate>Mon, 03 Jul 2006 15:03:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=104#comment-1011</guid>
		<description>&lt;p&gt;The place where the MySQL method of grouping is better is if you group on a foreign key column in the initial table. If for example you join to the table and wish to output say a description column, there is no need to group by the description column as you are already grouping on the primary key of the foreign table. E.g&lt;/p&gt;

&lt;pre&gt;select fd.FruitDescription, fd.FruitPrice, count(*) as c
from Fruits f
INNER JOIN fruitDescription fd ON f.fruitID = fd.ID
group by f.FruitID&lt;/pre&gt;

&lt;p&gt;There is no point in including the FruitDescription and FruitPrice columns in the group by as the primary key of the fruitDescription  table will always change before the description or price.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>The place where the MySQL method of grouping is better is if you group on a foreign key column in the initial table. If for example you join to the table and wish to output say a description column, there is no need to group by the description column as you are already grouping on the primary key of the foreign table. E.g</p>
<pre>select fd.FruitDescription, fd.FruitPrice, count(*) as c
from Fruits f
INNER JOIN fruitDescription fd ON f.fruitID = fd.ID
group by f.FruitID</pre>
<p>There is no point in including the FruitDescription and FruitPrice columns in the group by as the primary key of the fruitDescription  table will always change before the description or price.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
