<?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; 2005 &#8211; 2008 &#8211; Delete Duplicate Rows</title>
	<atom:link href="http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 09 Feb 2012 10:40:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; Convert Subquery to CTE &#8211; SQL in Sixty Seconds #001 &#8211; Video &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-249751</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Convert Subquery to CTE &#8211; SQL in Sixty Seconds #001 &#8211; Video &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Wed, 08 Feb 2012 01:32:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-249751</guid>
		<description><![CDATA[[...] CTE Multiple CTE in One SELECT Statement Query Common Table Expression (CTE) and Few Observation Delete Duplicate Rows Simple Example of Recursive CTE – Part 2 – MAXRECURSION – Prevent CTE Infinite Loop T-SQL [...]]]></description>
		<content:encoded><![CDATA[<p>[...] CTE Multiple CTE in One SELECT Statement Query Common Table Expression (CTE) and Few Observation Delete Duplicate Rows Simple Example of Recursive CTE – Part 2 – MAXRECURSION – Prevent CTE Infinite Loop T-SQL [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Hardwick</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-249623</link>
		<dc:creator><![CDATA[David Hardwick]]></dc:creator>
		<pubDate>Tue, 07 Feb 2012 17:31:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-249623</guid>
		<description><![CDATA[We have to insert 30,000 rows every 10 minutes...we do that for about an hour.  What is the best way to prevent duplicates?

a) Use a batch approach like the methods described in this article to remove duplicates
b) Use a real-time approach by adding a unique index to prevent duplicates when you insert?  

Thanks,
  David]]></description>
		<content:encoded><![CDATA[<p>We have to insert 30,000 rows every 10 minutes&#8230;we do that for about an hour.  What is the best way to prevent duplicates?</p>
<p>a) Use a batch approach like the methods described in this article to remove duplicates<br />
b) Use a real-time approach by adding a unique index to prevent duplicates when you insert?  </p>
<p>Thanks,<br />
  David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ajay babu</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-244497</link>
		<dc:creator><![CDATA[ajay babu]]></dc:creator>
		<pubDate>Fri, 27 Jan 2012 11:17:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-244497</guid>
		<description><![CDATA[This is for finding the duplicate rows:

duplicate rows=case 1-case2

SELECT Personentityid,COUNT(NAMESNO) AS DUPLICATE INTO DBA_DB.dbo.duplicatevalues FROM DBA_DB.dbo.SpellingVariation 
GROUP BY Personentityid

case 1:
select sum(duplicate) from DBA_DB.dbo.duplicatevalues where duplicate&gt;1

Case 2:
select Personentityid from DBA_DB.dbo.duplicatevalues where duplicate&gt;1]]></description>
		<content:encoded><![CDATA[<p>This is for finding the duplicate rows:</p>
<p>duplicate rows=case 1-case2</p>
<p>SELECT Personentityid,COUNT(NAMESNO) AS DUPLICATE INTO DBA_DB.dbo.duplicatevalues FROM DBA_DB.dbo.SpellingVariation<br />
GROUP BY Personentityid</p>
<p>case 1:<br />
select sum(duplicate) from DBA_DB.dbo.duplicatevalues where duplicate&gt;1</p>
<p>Case 2:<br />
select Personentityid from DBA_DB.dbo.duplicatevalues where duplicate&gt;1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; Common Gotcha&#8217;s Associated with Common Table Expressions (CTE) &#8211; Quiz &#8211; Puzzle &#8211; 26 of 31 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-244327</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Common Gotcha&#8217;s Associated with Common Table Expressions (CTE) &#8211; Quiz &#8211; Puzzle &#8211; 26 of 31 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Fri, 27 Jan 2012 01:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-244327</guid>
		<description><![CDATA[[...] Common Table Expression (CTE) and Few Observation Multiple CTE in One SELECT Statement Query Delete Duplicate Rows Simple Example of Recursive CTE SQL SERVER – Simple Example of Recursive CTE – Part 2 – [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Common Table Expression (CTE) and Few Observation Multiple CTE in One SELECT Statement Query Delete Duplicate Rows Simple Example of Recursive CTE SQL SERVER – Simple Example of Recursive CTE – Part 2 – [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phani</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-214038</link>
		<dc:creator><![CDATA[Phani]]></dc:creator>
		<pubDate>Fri, 09 Dec 2011 12:24:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-214038</guid>
		<description><![CDATA[Not Bad]]></description>
		<content:encoded><![CDATA[<p>Not Bad</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ramprasad</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-206649</link>
		<dc:creator><![CDATA[ramprasad]]></dc:creator>
		<pubDate>Mon, 28 Nov 2011 19:30:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-206649</guid>
		<description><![CDATA[Pinal you are doing a great job man.]]></description>
		<content:encoded><![CDATA[<p>Pinal you are doing a great job man.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-196937</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Wed, 16 Nov 2011 14:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-196937</guid>
		<description><![CDATA[@madhan

What do you mean by &quot;top 3&quot;
SELECT...FROM TABLE
EXCEPT
SELECT TOP(3) ...FROM TABLE ORDER BY...]]></description>
		<content:encoded><![CDATA[<p>@madhan</p>
<p>What do you mean by &#8220;top 3&#8243;<br />
SELECT&#8230;FROM TABLE<br />
EXCEPT<br />
SELECT TOP(3) &#8230;FROM TABLE ORDER BY&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhan</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-196687</link>
		<dc:creator><![CDATA[madhan]]></dc:creator>
		<pubDate>Wed, 16 Nov 2011 08:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-196687</guid>
		<description><![CDATA[hi sir i want a query in table i want to show all records  without top 3 records ?

any sqlquery please help me...madan]]></description>
		<content:encoded><![CDATA[<p>hi sir i want a query in table i want to show all records  without top 3 records ?</p>
<p>any sqlquery please help me&#8230;madan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Developer Mike</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-191786</link>
		<dc:creator><![CDATA[Developer Mike]]></dc:creator>
		<pubDate>Wed, 09 Nov 2011 19:07:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-191786</guid>
		<description><![CDATA[as always.. u r my savior.]]></description>
		<content:encoded><![CDATA[<p>as always.. u r my savior.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ChrisCarson</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-183880</link>
		<dc:creator><![CDATA[ChrisCarson]]></dc:creator>
		<pubDate>Wed, 26 Oct 2011 22:02:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-183880</guid>
		<description><![CDATA[This is a nifty use of a CTE.  My question is, how does using the CTE compare in terms of performance to using a SELECT DISTINCT?

The tables I am looking at text import tables.  They are all very wide with upwards of 50 columns, all of the columns are varchar(255).

( I didn&#039;t create the table but I have to maintain it! )

Duplicates would only exists if all 50 of the columns were identical.

The current query is a SELECT DISTINCT, but I wonder whether or not a CTE would be more efficient.

Maybe if I added a computed column that&#039;s a hash of all the columns, and looked for duplicates based on that column?]]></description>
		<content:encoded><![CDATA[<p>This is a nifty use of a CTE.  My question is, how does using the CTE compare in terms of performance to using a SELECT DISTINCT?</p>
<p>The tables I am looking at text import tables.  They are all very wide with upwards of 50 columns, all of the columns are varchar(255).</p>
<p>( I didn&#8217;t create the table but I have to maintain it! )</p>
<p>Duplicates would only exists if all 50 of the columns were identical.</p>
<p>The current query is a SELECT DISTINCT, but I wonder whether or not a CTE would be more efficient.</p>
<p>Maybe if I added a computed column that&#8217;s a hash of all the columns, and looked for duplicates based on that column?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alireza</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-174522</link>
		<dc:creator><![CDATA[Alireza]]></dc:creator>
		<pubDate>Mon, 03 Oct 2011 07:47:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-174522</guid>
		<description><![CDATA[I think I found it.
WITH CTE (R2,R3,R4,R5, DuplicateCount)
AS
(
SELECT R2,R3,R4,R5,
ROW_NUMBER() OVER(PARTITION BY R2,R3,R4,R5 ORDER BY R6,R7) AS DuplicateCount
FROM tBLtEST
)
DELETE
FROM CTE
WHERE DuplicateCount &gt; 1
GO 

Can you just check this and make me sure it is correct?]]></description>
		<content:encoded><![CDATA[<p>I think I found it.<br />
WITH CTE (R2,R3,R4,R5, DuplicateCount)<br />
AS<br />
(<br />
SELECT R2,R3,R4,R5,<br />
ROW_NUMBER() OVER(PARTITION BY R2,R3,R4,R5 ORDER BY R6,R7) AS DuplicateCount<br />
FROM tBLtEST<br />
)<br />
DELETE<br />
FROM CTE<br />
WHERE DuplicateCount &gt; 1<br />
GO </p>
<p>Can you just check this and make me sure it is correct?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alireza</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-174515</link>
		<dc:creator><![CDATA[Alireza]]></dc:creator>
		<pubDate>Mon, 03 Oct 2011 07:18:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-174515</guid>
		<description><![CDATA[Ok, here Iam.
these are the scripts (SQL Server 2005):
Table creation:
USE [MyDB]
GO
/****** Object:  Table [dbo].[tBLtEST]    Script Date: 10/03/2011 21:48:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tBLtEST](
	[R1] [varchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
	[R2] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R3] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R4] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R5] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R6] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R7] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R8] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R9] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[R10] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_tBLtEST] PRIMARY KEY CLUSTERED 
(
	[R1] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
---------------------------------------------------------------------------------

Data Insertion section:

INSERT INTO dbo.tBLtEST VALUES 
(&#039;1&#039;,&#039;R2&#039;,&#039;R3&#039;,&#039;R4&#039;,&#039;R5&#039;,NULL,NULL,NULL,NULL,NULL)--NORMAL RECORD
INSERT INTO dbo.tBLtEST VALUES 
(&#039;A&#039;,&#039;RR&#039;,&#039;RR3&#039;,&#039;RG4&#039;,&#039;RG5&#039;,&#039;RH6&#039;,&#039;RH7&#039;,&#039;RTJ&#039;,NULL,NULL)--NORMAL RECORD
INSERT INTO dbo.tBLtEST VALUES 
(&#039;B&#039;,&#039;RB2&#039;,&#039;RB3&#039;,&#039;RB4&#039;,&#039;RB5&#039;,NULL,&#039;KJL&#039;,&#039;LKJU&#039;,&#039;BBNJ&#039;,&#039;TEST&#039;)--NORMAL RECORD
INSERT INTO dbo.tBLtEST VALUES 
(&#039;C&#039;,&#039;R2&#039;,&#039;R3&#039;,&#039;R4&#039;,&#039;R5&#039;,&#039;R6&#039;,&#039;R7&#039;,NULL,NULL,NULL)--DUPLCATE RECORD WITH THE FIRST RECORD
INSERT INTO dbo.tBLtEST VALUES 
(&#039;D&#039;,&#039;DR2&#039;,&#039;DR3&#039;,&#039;DR4&#039;,&#039;DR5&#039;,NULL,NULL,NULL,NULL,NULL)
INSERT INTO dbo.tBLtEST VALUES 
(&#039;E&#039;,&#039;DR2&#039;,&#039;DR3&#039;,&#039;DR4&#039;,&#039;DR5&#039;,&#039;KK&#039;,&#039;NN&#039;,NULL,NULL,NULL)--DUPLICATE WITH ABOVE RECORD (pk=D)
INSERT INTO dbo.tBLtEST VALUES 
(&#039;F&#039;,&#039;RF2&#039;,&#039;RF3&#039;,&#039;FR4&#039;,&#039;FR5&#039;,&#039;FFFF&#039;,&#039;OOO&#039;,NULL,&#039;MMM&#039;,&#039;KKL&#039;)--NORMAL RECORD
INSERT INTO dbo.tBLtEST VALUES 
(&#039;G&#039;,&#039;RGG2&#039;,&#039;GGGR3&#039;,&#039;RGGG4&#039;,&#039;GGGR5&#039;,NULL,&#039;GGG&#039;,&#039;GHH&#039;,NULL,NULL)--NORMAL RECORD

----------------------------------------------------------

what i need is to remove the duplicates, but always remove the ones which the
R6 and R7 field are filled.
here in this sample i want to be sure that the Records C and E are removed.
hope it is clear now and you can guid me for that.
PS: please consider that I have Huge amount of data in the DB.
BRs,]]></description>
		<content:encoded><![CDATA[<p>Ok, here Iam.<br />
these are the scripts (SQL Server 2005):<br />
Table creation:<br />
USE [MyDB]<br />
GO<br />
/****** Object:  Table [dbo].[tBLtEST]    Script Date: 10/03/2011 21:48:04 ******/<br />
SET ANSI_NULLS ON<br />
GO<br />
SET QUOTED_IDENTIFIER ON<br />
GO<br />
SET ANSI_PADDING ON<br />
GO<br />
CREATE TABLE [dbo].[tBLtEST](<br />
	[R1] [varchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,<br />
	[R2] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R3] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R4] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R5] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R6] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R7] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R8] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R9] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
	[R10] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,<br />
 CONSTRAINT [PK_tBLtEST] PRIMARY KEY CLUSTERED<br />
(<br />
	[R1] ASC<br />
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]<br />
) ON [PRIMARY]</p>
<p>GO<br />
SET ANSI_PADDING OFF<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>Data Insertion section:</p>
<p>INSERT INTO dbo.tBLtEST VALUES<br />
(&#8217;1&#8242;,&#8217;R2&#8242;,&#8217;R3&#8242;,&#8217;R4&#8242;,&#8217;R5&#8242;,NULL,NULL,NULL,NULL,NULL)&#8211;NORMAL RECORD<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;A&#8217;,'RR&#8217;,'RR3&#8242;,&#8217;RG4&#8242;,&#8217;RG5&#8242;,&#8217;RH6&#8242;,&#8217;RH7&#8242;,&#8217;RTJ&#8217;,NULL,NULL)&#8211;NORMAL RECORD<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;B&#8217;,'RB2&#8242;,&#8217;RB3&#8242;,&#8217;RB4&#8242;,&#8217;RB5&#8242;,NULL,&#8217;KJL&#8217;,'LKJU&#8217;,'BBNJ&#8217;,'TEST&#8217;)&#8211;NORMAL RECORD<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;C&#8217;,'R2&#8242;,&#8217;R3&#8242;,&#8217;R4&#8242;,&#8217;R5&#8242;,&#8217;R6&#8242;,&#8217;R7&#8242;,NULL,NULL,NULL)&#8211;DUPLCATE RECORD WITH THE FIRST RECORD<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;D&#8217;,'DR2&#8242;,&#8217;DR3&#8242;,&#8217;DR4&#8242;,&#8217;DR5&#8242;,NULL,NULL,NULL,NULL,NULL)<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;E&#8217;,'DR2&#8242;,&#8217;DR3&#8242;,&#8217;DR4&#8242;,&#8217;DR5&#8242;,&#8217;KK&#8217;,'NN&#8217;,NULL,NULL,NULL)&#8211;DUPLICATE WITH ABOVE RECORD (pk=D)<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;F&#8217;,'RF2&#8242;,&#8217;RF3&#8242;,&#8217;FR4&#8242;,&#8217;FR5&#8242;,&#8217;FFFF&#8217;,'OOO&#8217;,NULL,&#8217;MMM&#8217;,'KKL&#8217;)&#8211;NORMAL RECORD<br />
INSERT INTO dbo.tBLtEST VALUES<br />
(&#8216;G&#8217;,'RGG2&#8242;,&#8217;GGGR3&#8242;,&#8217;RGGG4&#8242;,&#8217;GGGR5&#8242;,NULL,&#8217;GGG&#8217;,'GHH&#8217;,NULL,NULL)&#8211;NORMAL RECORD</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>what i need is to remove the duplicates, but always remove the ones which the<br />
R6 and R7 field are filled.<br />
here in this sample i want to be sure that the Records C and E are removed.<br />
hope it is clear now and you can guid me for that.<br />
PS: please consider that I have Huge amount of data in the DB.<br />
BRs,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alireza</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-174501</link>
		<dc:creator><![CDATA[Alireza]]></dc:creator>
		<pubDate>Mon, 03 Oct 2011 06:45:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-174501</guid>
		<description><![CDATA[Thank you so much.
I am providing the working script for you to clarify the case.
Thanks and Regards,]]></description>
		<content:encoded><![CDATA[<p>Thank you so much.<br />
I am providing the working script for you to clarify the case.<br />
Thanks and Regards,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-174495</link>
		<dc:creator><![CDATA[pinaldave]]></dc:creator>
		<pubDate>Mon, 03 Oct 2011 06:20:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-174495</guid>
		<description><![CDATA[Alireza you will need to send me working script to come up with answer for you. It is not possible to understand everything from your question.]]></description>
		<content:encoded><![CDATA[<p>Alireza you will need to send me working script to come up with answer for you. It is not possible to understand everything from your question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alireza</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-174177</link>
		<dc:creator><![CDATA[Alireza]]></dc:creator>
		<pubDate>Sun, 02 Oct 2011 10:59:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-174177</guid>
		<description><![CDATA[hi, Thanks for the article, it was so useful.
but i have another problem, similar to this:
My table has 10 rows, let say R1 to R10
R1 is the primary key .
i had some data while is filled in R1 to R5, and some else to R10.

The problem is: the system by mistake inserted duplicate data in R2-R5 (R1 is PK assuem autonumber) and in one of these duplicates R6 and R7 are also filled.
I want to remove the duplicates, which their R6,R7 are filled.
Consider that the R6,R7,... may be filled for other data, and they are ok!
by this method i could find them and remove the duplicates, but i cannot decide to remove which one! I mean I can not force to remove the duplicates which has R6,R7.
Please advice.]]></description>
		<content:encoded><![CDATA[<p>hi, Thanks for the article, it was so useful.<br />
but i have another problem, similar to this:<br />
My table has 10 rows, let say R1 to R10<br />
R1 is the primary key .<br />
i had some data while is filled in R1 to R5, and some else to R10.</p>
<p>The problem is: the system by mistake inserted duplicate data in R2-R5 (R1 is PK assuem autonumber) and in one of these duplicates R6 and R7 are also filled.<br />
I want to remove the duplicates, which their R6,R7 are filled.<br />
Consider that the R6,R7,&#8230; may be filled for other data, and they are ok!<br />
by this method i could find them and remove the duplicates, but i cannot decide to remove which one! I mean I can not force to remove the duplicates which has R6,R7.<br />
Please advice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakaravarthi</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-173507</link>
		<dc:creator><![CDATA[sakaravarthi]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 09:16:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-173507</guid>
		<description><![CDATA[comman Table Expression 

http://msdn.microsoft.com/en-us/library/ms190766.aspx]]></description>
		<content:encoded><![CDATA[<p>comman Table Expression </p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms190766.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190766.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakaravarthi</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-173506</link>
		<dc:creator><![CDATA[sakaravarthi]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 09:14:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-173506</guid>
		<description><![CDATA[WITH cte (clr,ROwNum)as 
(SELECT clr,row_Number() OVER(PARTITION BY LEFT(clr,CHARINDEX(SPACE(1),clr)-1) ORDER BY LEFT(clr,CHARINDEX(SPACE(1),clr)-1)) FROM color)
--select * from cte where ROwNum&gt;1
--select clr,CHARINDEX(SPACE(1),clr),
--LEFT(clr,CHARINDEX(SPACE(1),clr)-1),
UPDATE cte SET clr=Right(clr,len(clr)-CHARINDEX(SPACE(1),clr))--AS ToUpdate from cte 
WHERE ROwNum&gt;1]]></description>
		<content:encoded><![CDATA[<p>WITH cte (clr,ROwNum)as<br />
(SELECT clr,row_Number() OVER(PARTITION BY LEFT(clr,CHARINDEX(SPACE(1),clr)-1) ORDER BY LEFT(clr,CHARINDEX(SPACE(1),clr)-1)) FROM color)<br />
&#8211;select * from cte where ROwNum&gt;1<br />
&#8211;select clr,CHARINDEX(SPACE(1),clr),<br />
&#8211;LEFT(clr,CHARINDEX(SPACE(1),clr)-1),<br />
UPDATE cte SET clr=Right(clr,len(clr)-CHARINDEX(SPACE(1),clr))&#8211;AS ToUpdate from cte<br />
WHERE ROwNum&gt;1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakaravarthi</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-173500</link>
		<dc:creator><![CDATA[sakaravarthi]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 08:49:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-173500</guid>
		<description><![CDATA[select  LEFT(,20) from ]]></description>
		<content:encoded><![CDATA[<p>select  LEFT(,20) from</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakaravarthi</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-173497</link>
		<dc:creator><![CDATA[sakaravarthi]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 08:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-173497</guid>
		<description><![CDATA[select top 10 LEFT(,20) from ]]></description>
		<content:encoded><![CDATA[<p>select top 10 LEFT(,20) from</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakaravarthi</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-173495</link>
		<dc:creator><![CDATA[sakaravarthi]]></dc:creator>
		<pubDate>Fri, 30 Sep 2011 08:46:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-173495</guid>
		<description><![CDATA[select GETDATE(),DATEADD(Minute,15,getdate())]]></description>
		<content:encoded><![CDATA[<p>select GETDATE(),DATEADD(Minute,15,getdate())</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Me</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-168365</link>
		<dc:creator><![CDATA[Me]]></dc:creator>
		<pubDate>Thu, 15 Sep 2011 12:38:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-168365</guid>
		<description><![CDATA[If you&#039;re using 2008, why not use the &quot;undocumented&quot; feature of physloc?  Substitute your table for tablename and substitute the column which contains the duplicate values for columnwithdups.  Works rather nicely if I do say so myself.

delete
from dbo.tablename
where tablename.%%physloc%%
  NOT IN (Select min(b.%%physloc%%)
          from dbo.tablename b
          group by b.columnwithdups);]]></description>
		<content:encoded><![CDATA[<p>If you&#8217;re using 2008, why not use the &#8220;undocumented&#8221; feature of physloc?  Substitute your table for tablename and substitute the column which contains the duplicate values for columnwithdups.  Works rather nicely if I do say so myself.</p>
<p>delete<br />
from dbo.tablename<br />
where tablename.%%physloc%%<br />
  NOT IN (Select min(b.%%physloc%%)<br />
          from dbo.tablename b<br />
          group by b.columnwithdups);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tarak</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-152408</link>
		<dc:creator><![CDATA[Tarak]]></dc:creator>
		<pubDate>Mon, 01 Aug 2011 18:23:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-152408</guid>
		<description><![CDATA[Hi Pinal,

Could you give me help on the following?
1. How many parameters that CTE can accepts?
2. Shall we able to move duplicate data into another table and How to delete duplicate records simultaneously using CTE.? Let me explain my actual scenario. I have a table called Test. 

Test has the following data
Col1  Col2  Col3
------  ------  ------
101   abc    xyz
102   aaa    bbb
101   abc    xyz
101   abc    xyz
103   xxx      yyy
101   abc    xyz
101   abc    xyz
101   abc    xyz
101   abc    xyz
101   abc    xyz
:::::::::::::::::::::::::

I need to store the duplicate records in the table Test_duplicate. Could you tell me how to achieve it with CTE.

My require output is 

Test:

Col1 Col2 Col3
------  ----- -----
101   abc    xyz
102   aaa    bbb
103   xxx      yyy


Test_duplicate:
Col1 Col2  Col3
-----  -----   -----
101   abc    xyz
101   abc    xyz
101   abc    xyz
101   abc    xyz
101   abc    xyz
101   abc    xyz
101   abc    xyz
::::::::::::::::::::::::



Thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Could you give me help on the following?<br />
1. How many parameters that CTE can accepts?<br />
2. Shall we able to move duplicate data into another table and How to delete duplicate records simultaneously using CTE.? Let me explain my actual scenario. I have a table called Test. </p>
<p>Test has the following data<br />
Col1  Col2  Col3<br />
&#8212;&#8212;  &#8212;&#8212;  &#8212;&#8212;<br />
101   abc    xyz<br />
102   aaa    bbb<br />
101   abc    xyz<br />
101   abc    xyz<br />
103   xxx      yyy<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
:::::::::::::::::::::::::</p>
<p>I need to store the duplicate records in the table Test_duplicate. Could you tell me how to achieve it with CTE.</p>
<p>My require output is </p>
<p>Test:</p>
<p>Col1 Col2 Col3<br />
&#8212;&#8212;  &#8212;&#8211; &#8212;&#8211;<br />
101   abc    xyz<br />
102   aaa    bbb<br />
103   xxx      yyy</p>
<p>Test_duplicate:<br />
Col1 Col2  Col3<br />
&#8212;&#8211;  &#8212;&#8211;   &#8212;&#8211;<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
101   abc    xyz<br />
::::::::::::::::::::::::</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Database Worst Practices – New Town and New Job and New Disasters Journey to SQLAuthority</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-147565</link>
		<dc:creator><![CDATA[SQL SERVER – Database Worst Practices – New Town and New Job and New Disasters Journey to SQLAuthority]]></dc:creator>
		<pubDate>Tue, 12 Jul 2011 01:33:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-147565</guid>
		<description><![CDATA[[...] (Read more here) [...]]]></description>
		<content:encoded><![CDATA[<p>[...] (Read more here) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sivakumar</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-144419</link>
		<dc:creator><![CDATA[Sivakumar]]></dc:creator>
		<pubDate>Tue, 28 Jun 2011 12:56:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-144419</guid>
		<description><![CDATA[Nice Answer Pinaldave.  This will help to lot of ppl who is looking for good and better solution in database.]]></description>
		<content:encoded><![CDATA[<p>Nice Answer Pinaldave.  This will help to lot of ppl who is looking for good and better solution in database.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Penchal Reddy.U</title>
		<link>http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/#comment-144383</link>
		<dc:creator><![CDATA[Penchal Reddy.U]]></dc:creator>
		<pubDate>Tue, 28 Jun 2011 10:34:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5631#comment-144383</guid>
		<description><![CDATA[very nice article.....great job....


Thanks,
U.Penchal Reddy.]]></description>
		<content:encoded><![CDATA[<p>very nice article&#8230;..great job&#8230;.</p>
<p>Thanks,<br />
U.Penchal Reddy.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

