<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; DISTINCT Keyword Usage and Common Discussion</title>
	<atom:link href="http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:22:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Veeresh</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-206430</link>
		<dc:creator><![CDATA[Veeresh]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 11:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-206430</guid>
		<description><![CDATA[shal i use..Distinct(Columname) like this]]></description>
		<content:encoded><![CDATA[<p>shal i use..Distinct(Columname) like this</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christof Coetzee</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-198498</link>
		<dc:creator><![CDATA[Christof Coetzee]]></dc:creator>
		<pubDate>Fri, 18 Nov 2011 11:11:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-198498</guid>
		<description><![CDATA[Hawing worked extensively with MySQL and only about 2 years on Sql Server I have encountered a lot of headaches with Sql Server&#039;s group-by, distinct and in general to get UNIQUE ROWS on joins.
The fact that you have to include all columns in a group-by is just silly and I think Sql Server is perhaps not as intelligent as MySql in its query plans.

In Sql Server the way to get recordsets for pagination is also unnecessarily complex TOP X and order-by, OVER PARTITION etc is ridiculous, in MySQL its as simple as LIMIT offset count.]]></description>
		<content:encoded><![CDATA[<p>Hawing worked extensively with MySQL and only about 2 years on Sql Server I have encountered a lot of headaches with Sql Server&#8217;s group-by, distinct and in general to get UNIQUE ROWS on joins.<br />
The fact that you have to include all columns in a group-by is just silly and I think Sql Server is perhaps not as intelligent as MySql in its query plans.</p>
<p>In Sql Server the way to get recordsets for pagination is also unnecessarily complex TOP X and order-by, OVER PARTITION etc is ridiculous, in MySQL its as simple as LIMIT offset count.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-154076</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 05 Aug 2011 10:05:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-154076</guid>
		<description><![CDATA[Can you post the code you have used? If you used group by clause, you dont need a distinct clause]]></description>
		<content:encoded><![CDATA[<p>Can you post the code you have used? If you used group by clause, you dont need a distinct clause</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shirish Kulkarni</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-154045</link>
		<dc:creator><![CDATA[Shirish Kulkarni]]></dc:creator>
		<pubDate>Fri, 05 Aug 2011 08:41:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-154045</guid>
		<description><![CDATA[As distinct clause affects performance of the application. What is the better option to DISTINCT clause. In T- SQL only.]]></description>
		<content:encoded><![CDATA[<p>As distinct clause affects performance of the application. What is the better option to DISTINCT clause. In T- SQL only.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AndresP</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-111757</link>
		<dc:creator><![CDATA[AndresP]]></dc:creator>
		<pubDate>Tue, 18 Jan 2011 18:19:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-111757</guid>
		<description><![CDATA[I have

select distinct a,b,c,database from
(
select a,b,c,&#039;A&#039; as database from tableA
union
select a,b,c,&#039;B&#039; as database from tableB
) as Everything

with tableA and tableB having lots of data in common, and I expect this query to give all the rows with different value of a.

Where&#039;s the logical error? Is there any way to have this simple query done in SQLServer?]]></description>
		<content:encoded><![CDATA[<p>I have</p>
<p>select distinct a,b,c,database from<br />
(<br />
select a,b,c,&#8217;A&#8217; as database from tableA<br />
union<br />
select a,b,c,&#8217;B&#8217; as database from tableB<br />
) as Everything</p>
<p>with tableA and tableB having lots of data in common, and I expect this query to give all the rows with different value of a.</p>
<p>Where&#8217;s the logical error? Is there any way to have this simple query done in SQLServer?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prithviraj MK</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-83591</link>
		<dc:creator><![CDATA[Prithviraj MK]]></dc:creator>
		<pubDate>Tue, 10 Aug 2010 12:42:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-83591</guid>
		<description><![CDATA[Hi,

I would like to know wether the distinct can be applied to each column in a table or not... if so can you please 
explain..

e.g.

I have a table containing a firstname, lastname, salary, designation, dob, doj,

----
I would like to apply distinct keyword for all the column in a table.

Thanks in Advance,
Prithviraj MK]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I would like to know wether the distinct can be applied to each column in a table or not&#8230; if so can you please<br />
explain..</p>
<p>e.g.</p>
<p>I have a table containing a firstname, lastname, salary, designation, dob, doj,</p>
<p>&#8212;-<br />
I would like to apply distinct keyword for all the column in a table.</p>
<p>Thanks in Advance,<br />
Prithviraj MK</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edolmen Sviluppo Siti Web</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-74090</link>
		<dc:creator><![CDATA[Edolmen Sviluppo Siti Web]]></dc:creator>
		<pubDate>Tue, 01 Jun 2010 09:18:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-74090</guid>
		<description><![CDATA[I’m actually working on a sample of 100 records from a 10,000 record table. The table has the following columns ( ID, PayerID, Category, Status, CreateDate )

In my  file I need to have a 100 records with all the columns but each record should have a DISTINCT PayerID.
How would I do that ?]]></description>
		<content:encoded><![CDATA[<p>I’m actually working on a sample of 100 records from a 10,000 record table. The table has the following columns ( ID, PayerID, Category, Status, CreateDate )</p>
<p>In my  file I need to have a 100 records with all the columns but each record should have a DISTINCT PayerID.<br />
How would I do that ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tejas Shah</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-65906</link>
		<dc:creator><![CDATA[Tejas Shah]]></dc:creator>
		<pubDate>Wed, 21 Apr 2010 10:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-65906</guid>
		<description><![CDATA[Hi Shaf,

If you are using SQL 2005 and above, you can use following:

;with cte as(
SELECT  Row_NUMBER() OVER(PARTITION BY Person ORDER BY Person) AS RowID,
*
from table
)
select * 
from cte
where RowID &gt; 1

It will list out all records that you need to delete. If you are sure that you can delete this. use this query:

;with cte as(
SELECT  Row_NUMBER() OVER(PARTITION BY Person ORDER BY Person) AS RowID,
*
from table
)
DELETE
from cte
where RowID &gt; 1

For more information: http://www.sqlyoga.com/2009/03/sql-server-find-duplicate-rows-with.html

Thanks,
Tejas]]></description>
		<content:encoded><![CDATA[<p>Hi Shaf,</p>
<p>If you are using SQL 2005 and above, you can use following:</p>
<p>;with cte as(<br />
SELECT  Row_NUMBER() OVER(PARTITION BY Person ORDER BY Person) AS RowID,<br />
*<br />
from table<br />
)<br />
select *<br />
from cte<br />
where RowID &gt; 1</p>
<p>It will list out all records that you need to delete. If you are sure that you can delete this. use this query:</p>
<p>;with cte as(<br />
SELECT  Row_NUMBER() OVER(PARTITION BY Person ORDER BY Person) AS RowID,<br />
*<br />
from table<br />
)<br />
DELETE<br />
from cte<br />
where RowID &gt; 1</p>
<p>For more information: <a href="http://www.sqlyoga.com/2009/03/sql-server-find-duplicate-rows-with.html" rel="nofollow">http://www.sqlyoga.com/2009/03/sql-server-find-duplicate-rows-with.html</a></p>
<p>Thanks,<br />
Tejas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shaf</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-65880</link>
		<dc:creator><![CDATA[shaf]]></dc:creator>
		<pubDate>Wed, 21 Apr 2010 08:05:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-65880</guid>
		<description><![CDATA[and one more thing here is in this table their is no autonumber or primary key,

i have to select only one person record and delet his duplicate entries ... that person records at a time]]></description>
		<content:encoded><![CDATA[<p>and one more thing here is in this table their is no autonumber or primary key,</p>
<p>i have to select only one person record and delet his duplicate entries &#8230; that person records at a time</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shaf</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-65871</link>
		<dc:creator><![CDATA[shaf]]></dc:creator>
		<pubDate>Wed, 21 Apr 2010 06:59:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-65871</guid>
		<description><![CDATA[How to select only one category of dupliacte records and delete that excluding one ...
for example consider in my DB table i have 200 records
in that i have more that one person duplicate records, now
i want to delete one user duplicate records.
that is if person one has entered his data 5 times with same details, i have to check that and have to delete 4 record of that person and keep one record... i may have more than one person records in that way in same table]]></description>
		<content:encoded><![CDATA[<p>How to select only one category of dupliacte records and delete that excluding one &#8230;<br />
for example consider in my DB table i have 200 records<br />
in that i have more that one person duplicate records, now<br />
i want to delete one user duplicate records.<br />
that is if person one has entered his data 5 times with same details, i have to check that and have to delete 4 record of that person and keep one record&#8230; i may have more than one person records in that way in same table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-52041</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Tue, 19 May 2009 04:04:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-52041</guid>
		<description><![CDATA[@Kinara, 

Need more details. 

Do you have duplicate records for the same PayerID with different combinations of ID&lt; Category, Status and CreateDate. If there exusts multiple records for same PayerID, I dont think, you can achieve your tasks by a simple select statement. 

Please provide some sample data.

Input and what kind of output you are expecting.

~ IM.]]></description>
		<content:encoded><![CDATA[<p>@Kinara, </p>
<p>Need more details. </p>
<p>Do you have duplicate records for the same PayerID with different combinations of ID&lt; Category, Status and CreateDate. If there exusts multiple records for same PayerID, I dont think, you can achieve your tasks by a simple select statement. </p>
<p>Please provide some sample data.</p>
<p>Input and what kind of output you are expecting.</p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kinara</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-52027</link>
		<dc:creator><![CDATA[Kinara]]></dc:creator>
		<pubDate>Mon, 18 May 2009 22:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-52027</guid>
		<description><![CDATA[I&#039;m surprised at your statement about &quot; logical error in thinking query like that... &quot;

I have a situation where I&#039;m asked for a sample of 100 records from a 10,000 record table. The table has the following columns ( ID, PayerID, Category, Status, CreateDate )

In my Sample file I need to have a 100 records with all the columns but each record should have a DISTINCT PayerID.

Explain to me please on how would you solve this? 


Thanx

Kinara]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m surprised at your statement about &#8221; logical error in thinking query like that&#8230; &#8221;</p>
<p>I have a situation where I&#8217;m asked for a sample of 100 records from a 10,000 record table. The table has the following columns ( ID, PayerID, Category, Status, CreateDate )</p>
<p>In my Sample file I need to have a 100 records with all the columns but each record should have a DISTINCT PayerID.</p>
<p>Explain to me please on how would you solve this? </p>
<p>Thanx</p>
<p>Kinara</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-50665</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Wed, 08 Apr 2009 04:32:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-50665</guid>
		<description><![CDATA[@Naeem

One way to do that is use GROUP BY, But there is a serious problem with GROUP BY, which I hate saying but true, You have to include all the columns in GROUP BY clause what you have mentioned in SELECT clause. 

Anyways your best choice would be to use OVER PARTITION BY in your select query, this is a new feature in sql server 2005.

OVER PARTITION BY will serves your purpose. This is just like GROUP BY but here you have freedom to exclude columns that you do not want to include in GROUP BY clause.

GROUP BY is nothing but grouping or distinct (for that match of columns) in a way.

Find simple example of OVER PARTITION BY here, 

http://www.sqlteam.com/article/sql-sever-2005-using-over-with-aggregate-functions

~ IM.]]></description>
		<content:encoded><![CDATA[<p>@Naeem</p>
<p>One way to do that is use GROUP BY, But there is a serious problem with GROUP BY, which I hate saying but true, You have to include all the columns in GROUP BY clause what you have mentioned in SELECT clause. </p>
<p>Anyways your best choice would be to use OVER PARTITION BY in your select query, this is a new feature in sql server 2005.</p>
<p>OVER PARTITION BY will serves your purpose. This is just like GROUP BY but here you have freedom to exclude columns that you do not want to include in GROUP BY clause.</p>
<p>GROUP BY is nothing but grouping or distinct (for that match of columns) in a way.</p>
<p>Find simple example of OVER PARTITION BY here, </p>
<p><a href="http://www.sqlteam.com/article/sql-sever-2005-using-over-with-aggregate-functions" rel="nofollow">http://www.sqlteam.com/article/sql-sever-2005-using-over-with-aggregate-functions</a></p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naeem</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-50652</link>
		<dc:creator><![CDATA[Naeem]]></dc:creator>
		<pubDate>Tue, 07 Apr 2009 23:34:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-50652</guid>
		<description><![CDATA[Hi, 

I have a similar problem but cant fix it can you please help me, problem is:

I have a table with following columns: basketid, lookup_value, date_time.
 
I only want to return distinct basketid and lookup value rows and also want to include date_time row as well. but it is not distinct. any solutions please. Group by and distinct does not solve my problem.

Thank you]]></description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I have a similar problem but cant fix it can you please help me, problem is:</p>
<p>I have a table with following columns: basketid, lookup_value, date_time.</p>
<p>I only want to return distinct basketid and lookup value rows and also want to include date_time row as well. but it is not distinct. any solutions please. Group by and distinct does not solve my problem.</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: parthiban</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-43527</link>
		<dc:creator><![CDATA[parthiban]]></dc:creator>
		<pubDate>Mon, 06 Oct 2008 07:08:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-43527</guid>
		<description><![CDATA[h i
 using stored produce  i want to remove the  duplicate value in the single colums]]></description>
		<content:encoded><![CDATA[<p>h i<br />
 using stored produce  i want to remove the  duplicate value in the single colums</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-42355</link>
		<dc:creator><![CDATA[Steven]]></dc:creator>
		<pubDate>Wed, 03 Sep 2008 09:07:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-42355</guid>
		<description><![CDATA[It seems to me that M$ SQL Server cannot &quot;GROUP BY&quot; one column of a result set, nor can it select only &quot;DISTINCT&quot; values of one column of the result set.

MySQL can easily do this with the following code: 
&quot;SELECT DISTINCT Roles, FirstName, LastName FROM UserNames&quot;]]></description>
		<content:encoded><![CDATA[<p>It seems to me that M$ SQL Server cannot &#8220;GROUP BY&#8221; one column of a result set, nor can it select only &#8220;DISTINCT&#8221; values of one column of the result set.</p>
<p>MySQL can easily do this with the following code:<br />
&#8220;SELECT DISTINCT Roles, FirstName, LastName FROM UserNames&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dash</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-34575</link>
		<dc:creator><![CDATA[Dash]]></dc:creator>
		<pubDate>Wed, 26 Mar 2008 06:10:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-34575</guid>
		<description><![CDATA[my concept is not clear after reading your discussion]]></description>
		<content:encoded><![CDATA[<p>my concept is not clear after reading your discussion</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roman</title>
		<link>http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-28109</link>
		<dc:creator><![CDATA[Roman]]></dc:creator>
		<pubDate>Sat, 22 Dec 2007 01:36:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/20/sql-server-distinct-keyword-usage-and-common-discussion/#comment-28109</guid>
		<description><![CDATA[In the following sentence you made a mistake: &quot;Distinct can not be applied to only few columns it is always applied to whole column.&quot; You must have meant the &quot;whole row&quot;, not column. And while at it, you may want to add a punctuation sign in front of &quot;it is...&quot;. :)]]></description>
		<content:encoded><![CDATA[<p>In the following sentence you made a mistake: &#8220;Distinct can not be applied to only few columns it is always applied to whole column.&#8221; You must have meant the &#8220;whole row&#8221;, not column. And while at it, you may want to add a punctuation sign in front of &#8220;it is&#8230;&#8221;. :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

