<?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: GROUP BY v DISTINCT (group by wins!)	</title>
	<atom:link href="https://lobsterpot.com.au/blog/2007/03/24/group-by-v-distinct-group-by-wins/feed/" rel="self" type="application/rss+xml" />
	<link>https://lobsterpot.com.au/blog/2007/03/24/group-by-v-distinct-group-by-wins/</link>
	<description></description>
	<lastBuildDate>Tue, 29 May 2018 01:28:17 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>
		By: Rob Farley		</title>
		<link>https://lobsterpot.com.au/blog/2007/03/24/group-by-v-distinct-group-by-wins/#comment-277</link>

		<dc:creator><![CDATA[Rob Farley]]></dc:creator>
		<pubDate>Tue, 29 May 2018 01:28:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/robfarley/archive/2007/03/24/group-by-v-distinct-group-by-wins.aspx#comment-277</guid>

					<description><![CDATA[Yes, that&#039;s the situation. Your query simulates GROUP BY by separating out the grouping. But I would be reluctant to encourage this pattern because too many people do a separate GROUP BY and then join back to the original table, when all they mean is &quot;GROUP BY the right things!&quot;]]></description>
			<content:encoded><![CDATA[<p>Yes, that&#8217;s the situation. Your query simulates GROUP BY by separating out the grouping. But I would be reluctant to encourage this pattern because too many people do a separate GROUP BY and then join back to the original table, when all they mean is &#8220;GROUP BY the right things!&#8221;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: José		</title>
		<link>https://lobsterpot.com.au/blog/2007/03/24/group-by-v-distinct-group-by-wins/#comment-276</link>

		<dc:creator><![CDATA[José]]></dc:creator>
		<pubDate>Tue, 29 May 2018 01:15:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/robfarley/archive/2007/03/24/group-by-v-distinct-group-by-wins.aspx#comment-276</guid>

					<description><![CDATA[Try

with uniqueT1 as (
SELECT distinct id
  from t1
)
SELECT id,
       stuff((SELECT &#039;,&#039; + t.[name]
                from t1 t
                where t.id = ut1.id
                order by t.[name]
                for xml path(&#039;&#039;)),
             1, 1, &#039;&#039;) as name_csv
  from uniqueT1 as ut1;

-----
Whenever repeated lines occur in the final result, the trick is not to use either DISTINCT or GROUP BY to eliminate the repetitions, but to look for the cause of the repetitions and eliminate them at the beginning.

The above code generates the same execution plan as the one you exemplify using GROUP BY.]]></description>
			<content:encoded><![CDATA[<p>Try</p>
<p>with uniqueT1 as (<br />
SELECT distinct id<br />
  from t1<br />
)<br />
SELECT id,<br />
       stuff((SELECT &#8216;,&#8217; + t.[name]<br />
                from t1 t<br />
                where t.id = ut1.id<br />
                order by t.[name]<br />
                for xml path(&#8221;)),<br />
             1, 1, &#8221;) as name_csv<br />
  from uniqueT1 as ut1;</p>
<p>&#8212;&#8211;<br />
Whenever repeated lines occur in the final result, the trick is not to use either DISTINCT or GROUP BY to eliminate the repetitions, but to look for the cause of the repetitions and eliminate them at the beginning.</p>
<p>The above code generates the same execution plan as the one you exemplify using GROUP BY.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rob Farley		</title>
		<link>https://lobsterpot.com.au/blog/2007/03/24/group-by-v-distinct-group-by-wins/#comment-275</link>

		<dc:creator><![CDATA[Rob Farley]]></dc:creator>
		<pubDate>Tue, 05 Jun 2007 06:46:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/robfarley/archive/2007/03/24/group-by-v-distinct-group-by-wins.aspx#comment-275</guid>

					<description><![CDATA[COALESCE only helps handle the situations where the string is null. It doesn&#039;t actually assist with the concatenation process itself.]]></description>
			<content:encoded><![CDATA[<p>COALESCE only helps handle the situations where the string is null. It doesn&#8217;t actually assist with the concatenation process itself.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Coalesce is not the answer to string concatentation in T-SQL		</title>
		<link>https://lobsterpot.com.au/blog/2007/03/24/group-by-v-distinct-group-by-wins/#comment-274</link>

		<dc:creator><![CDATA[Coalesce is not the answer to string concatentation in T-SQL]]></dc:creator>
		<pubDate>Tue, 05 Jun 2007 06:35:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/robfarley/archive/2007/03/24/group-by-v-distinct-group-by-wins.aspx#comment-274</guid>

					<description><![CDATA[Rob, If u do not wants to use COALESCE function in ur T-SQL, then u can use CASE statements for String concatenation.

What say?

Mahesh]]></description>
			<content:encoded><![CDATA[<p>Rob, If u do not wants to use COALESCE function in ur T-SQL, then u can use CASE statements for String concatenation.</p>
<p>What say?</p>
<p>Mahesh</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
