 




<?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: Viewing distinct records in a SQL query result</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/viewing-distinct-records-in-a-sql-query-result/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/viewing-distinct-records-in-a-sql-query-result/</link>
	<description></description>
	<lastBuildDate>Sat, 18 May 2013 17:13:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/viewing-distinct-records-in-a-sql-query-result/#comment-61993</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Tue, 07 Apr 2009 23:30:14 +0000</pubDate>
		<guid isPermaLink="false">#comment-61993</guid>
		<description><![CDATA[You are absolutely correct Kccrosser.
I have seen similar situations many times, most of them, due to incorrect join conditions.
Thanks for complementing the answer.]]></description>
		<content:encoded><![CDATA[<p>You are absolutely correct Kccrosser.<br />
I have seen similar situations many times, most of them, due to incorrect join conditions.<br />
Thanks for complementing the answer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/viewing-distinct-records-in-a-sql-query-result/#comment-61931</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Mon, 06 Apr 2009 20:45:01 +0000</pubDate>
		<guid isPermaLink="false">#comment-61931</guid>
		<description><![CDATA[Carlosdl is correct on the problem and a suggested fix.

Caution - pedantic rant follows - I am loathe to use &quot;DISTINCT&quot; in queries, unless I thoroughly understand why I am getting duplicate rows back.  I have seen way too many queries that use DISTINCT to discard &quot;excess&quot; rows that are being caused by a poorly constructed query.

DISTINCT is too often used to cover up a multitude of query problems, including Cartesian product queries, and I have (very recently) seen queries that appear to return a nicely formed set of 20 or so result records, but when analyzed further, turn out ot be generating an intermediate result of over 15,000 records due to a missing join condition, then discarding 14,980 of them as &quot;dups&quot; due to the DISTINCT keyword.

And then users and DBAs wonder why their systems seem to be running slowly...]]></description>
		<content:encoded><![CDATA[<p>Carlosdl is correct on the problem and a suggested fix.</p>
<p>Caution &#8211; pedantic rant follows &#8211; I am loathe to use &#8220;DISTINCT&#8221; in queries, unless I thoroughly understand why I am getting duplicate rows back.  I have seen way too many queries that use DISTINCT to discard &#8220;excess&#8221; rows that are being caused by a poorly constructed query.</p>
<p>DISTINCT is too often used to cover up a multitude of query problems, including Cartesian product queries, and I have (very recently) seen queries that appear to return a nicely formed set of 20 or so result records, but when analyzed further, turn out ot be generating an intermediate result of over 15,000 records due to a missing join condition, then discarding 14,980 of them as &#8220;dups&#8221; due to the DISTINCT keyword.</p>
<p>And then users and DBAs wonder why their systems seem to be running slowly&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/viewing-distinct-records-in-a-sql-query-result/#comment-61860</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Fri, 03 Apr 2009 18:03:04 +0000</pubDate>
		<guid isPermaLink="false">#comment-61860</guid>
		<description><![CDATA[The DISTINCT keyword will filter out those records in which all fields are exactly the same as some other record, that&#039;s why you are not getting the result you expected.

You will need to define a criteria the choose what is the &#039;first&#039; record, since the information will not neccesary come in the same order from the database every time you run your query, unless you specify some criteria to order by.

This could be one way to do it:

&lt;pre&gt;SELECT id, min(description)
FROM YourTable
GROUP BY id;&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>The DISTINCT keyword will filter out those records in which all fields are exactly the same as some other record, that&#8217;s why you are not getting the result you expected.</p>
<p>You will need to define a criteria the choose what is the &#8216;first&#8217; record, since the information will not neccesary come in the same order from the database every time you run your query, unless you specify some criteria to order by.</p>
<p>This could be one way to do it:</p>
<pre>SELECT id, min(description)
FROM YourTable
GROUP BY id;</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/9 queries in 0.015 seconds using memcached
Object Caching 296/299 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-18 18:08:07 -->