<?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; Delete Duplicate Records &#8211; Rows</title>
	<atom:link href="http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 09 Feb 2012 10:31:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Garry</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-244400</link>
		<dc:creator><![CDATA[Garry]]></dc:creator>
		<pubDate>Fri, 27 Jan 2012 06:18:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-244400</guid>
		<description><![CDATA[select distinct * into dbo.table_new from dbo.table_duplicates

This will copy all distinct rows from one table, create a new table and insert the distinct rows only.]]></description>
		<content:encoded><![CDATA[<p>select distinct * into dbo.table_new from dbo.table_duplicates</p>
<p>This will copy all distinct rows from one table, create a new table and insert the distinct rows only.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mahesh</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-227264</link>
		<dc:creator><![CDATA[mahesh]]></dc:creator>
		<pubDate>Wed, 28 Dec 2011 07:45:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-227264</guid>
		<description><![CDATA[hoe can improve query performance, hear no need use indexes or vies ect,   forexample select * from my table query execution time is 5 min but i want execute it with in a 2min how can it posible, plz give me rply]]></description>
		<content:encoded><![CDATA[<p>hoe can improve query performance, hear no need use indexes or vies ect,   forexample select * from my table query execution time is 5 min but i want execute it with in a 2min how can it posible, plz give me rply</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mahesh</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-227258</link>
		<dc:creator><![CDATA[mahesh]]></dc:creator>
		<pubDate>Wed, 28 Dec 2011 07:30:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-227258</guid>
		<description><![CDATA[hi,

how can we improve query performence. with same query dont use indexes view .   for example select * from mytable query execute 2 min  but the same query i want execute with in 1 min. hw can we do that one , please give me reply]]></description>
		<content:encoded><![CDATA[<p>hi,</p>
<p>how can we improve query performence. with same query dont use indexes view .   for example select * from mytable query execute 2 min  but the same query i want execute with in 1 min. hw can we do that one , please give me reply</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanjeev Singh</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-222018</link>
		<dc:creator><![CDATA[Sanjeev Singh]]></dc:creator>
		<pubDate>Tue, 20 Dec 2011 10:30:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-222018</guid>
		<description><![CDATA[We can use INTERSECTION on same table to fetch unique records by following query,


SELECT * into DupRecordsTbl_bkp FROM
(SELECT * FROM DupRecordsTbl INTERSECT SELECT * FROM DupRecordsTbl)B
DELETE FROM DupRecordsTbl
INSERT INTO DupRecordsTbl SELECT * FROM DupRecordsTbl_bkp

Keeps the unique record into a new table. Deletes the original table records and reinsert the unique records into original table.

Here we need no info about columns as it compares the whole row.]]></description>
		<content:encoded><![CDATA[<p>We can use INTERSECTION on same table to fetch unique records by following query,</p>
<p>SELECT * into DupRecordsTbl_bkp FROM<br />
(SELECT * FROM DupRecordsTbl INTERSECT SELECT * FROM DupRecordsTbl)B<br />
DELETE FROM DupRecordsTbl<br />
INSERT INTO DupRecordsTbl SELECT * FROM DupRecordsTbl_bkp</p>
<p>Keeps the unique record into a new table. Deletes the original table records and reinsert the unique records into original table.</p>
<p>Here we need no info about columns as it compares the whole row.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prakash</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-203591</link>
		<dc:creator><![CDATA[prakash]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 10:27:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-203591</guid>
		<description><![CDATA[Here is an another query where we could use to delete the duplicate rows...


delete from table where table.%%physloc%% not in (select MIN(%%physloc%%) from table
group by duplicate columns)]]></description>
		<content:encoded><![CDATA[<p>Here is an another query where we could use to delete the duplicate rows&#8230;</p>
<p>delete from table where table.%%physloc%% not in (select MIN(%%physloc%%) from table<br />
group by duplicate columns)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stuff</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-203558</link>
		<dc:creator><![CDATA[stuff]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 09:15:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-203558</guid>
		<description><![CDATA[...This is how it looks

CustomerID      Name      Address   ...
2101                  ABC      123 blaa
2101                  WQH     123 blaa

The Name and Address should remain the same but the CustomerID must be changed

Thank you]]></description>
		<content:encoded><![CDATA[<p>&#8230;This is how it looks</p>
<p>CustomerID      Name      Address   &#8230;<br />
2101                  ABC      123 blaa<br />
2101                  WQH     123 blaa</p>
<p>The Name and Address should remain the same but the CustomerID must be changed</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stuff</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-203539</link>
		<dc:creator><![CDATA[stuff]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 08:42:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-203539</guid>
		<description><![CDATA[Hi Sir

I am in a situation where I have the same CustomerID&#039;s but different Customer names. They belong to the same Subsidiary Entity so the phone numbers and address must remain the same..

Please help]]></description>
		<content:encoded><![CDATA[<p>Hi Sir</p>
<p>I am in a situation where I have the same CustomerID&#8217;s but different Customer names. They belong to the same Subsidiary Entity so the phone numbers and address must remain the same..</p>
<p>Please help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Varun</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-178363</link>
		<dc:creator><![CDATA[Varun]]></dc:creator>
		<pubDate>Thu, 13 Oct 2011 11:43:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-178363</guid>
		<description><![CDATA[The columns are date, name, product and quantity.]]></description>
		<content:encoded><![CDATA[<p>The columns are date, name, product and quantity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Varun</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-178358</link>
		<dc:creator><![CDATA[Varun]]></dc:creator>
		<pubDate>Thu, 13 Oct 2011 11:38:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-178358</guid>
		<description><![CDATA[I have a quite different request :

Below is the table with sample data that I have
 
Date                        Name                   Product              Quantity
10/11/2011              Aname                 Abc1                          20
10/10/2011              Aname                 Abc1                          20
10/9/2011              Aname                   Abc1                          20
10/8/2011              AName                   Xyz1                           30
10/7/2011              AName                   Xyz1                           20
10/6/2011              AName                    Abc1                        20
10/5/2011              AName                    Abc1                        20
10/4/2011              BName                   Xyz1                           30
10/11/2011              Bname                 Abc2                          20
10/10/2011              Bname                 Abc2                          20
10/9/2011              Bname                   Abc2                         20
10/8/2011              BName                   Xyz2                         30
10/7/2011              BName                   Xyz2                          20
10/6/2011              BName                    Abc2                        20
10/5/2011              BName                    Abc2                        20
10/4/2011              BName                   Xyz2                           30


Output should be :

 Id     Start Date                EndDate               Name       Product    Quantity
1         10/9/2011             10/11/2011            Aname      Abc1            20
2         10/8/2011             10/9/2011              Aname      Xyz1            30
3         10/7/2011             10/8/2011              Aname      Xyz1            20
4         10/5/2011             10/7/2011              Aname      Abc1            20
5         10/4/2011             10/5/2011              Aname      Xyz1            30
6         10/9/2011             10/11/2011            Bname      Abc2            20
7         10/8/2011             10/9/2011              Bname      Xyz2            30
8         10/7/2011             10/8/2011              Bname      Xyz2            20
9         10/5/2011             10/7/2011              Bname      Abc2           20
10         10/4/2011             10/5/2011             Bname     Xyz2           30



I do not have primary key on my Table.

If you see the number of rows have been reduced.

 I have more than 500 million records and by filtering this I would significantly the number of records in the table.

Is there any efficient query or sproc to do this, if so could you please help me.


I have tried using group by , partitions, ranking but nothing worked .


Thanks &amp; Regards,

VPandit.]]></description>
		<content:encoded><![CDATA[<p>I have a quite different request :</p>
<p>Below is the table with sample data that I have</p>
<p>Date                        Name                   Product              Quantity<br />
10/11/2011              Aname                 Abc1                          20<br />
10/10/2011              Aname                 Abc1                          20<br />
10/9/2011              Aname                   Abc1                          20<br />
10/8/2011              AName                   Xyz1                           30<br />
10/7/2011              AName                   Xyz1                           20<br />
10/6/2011              AName                    Abc1                        20<br />
10/5/2011              AName                    Abc1                        20<br />
10/4/2011              BName                   Xyz1                           30<br />
10/11/2011              Bname                 Abc2                          20<br />
10/10/2011              Bname                 Abc2                          20<br />
10/9/2011              Bname                   Abc2                         20<br />
10/8/2011              BName                   Xyz2                         30<br />
10/7/2011              BName                   Xyz2                          20<br />
10/6/2011              BName                    Abc2                        20<br />
10/5/2011              BName                    Abc2                        20<br />
10/4/2011              BName                   Xyz2                           30</p>
<p>Output should be :</p>
<p> Id     Start Date                EndDate               Name       Product    Quantity<br />
1         10/9/2011             10/11/2011            Aname      Abc1            20<br />
2         10/8/2011             10/9/2011              Aname      Xyz1            30<br />
3         10/7/2011             10/8/2011              Aname      Xyz1            20<br />
4         10/5/2011             10/7/2011              Aname      Abc1            20<br />
5         10/4/2011             10/5/2011              Aname      Xyz1            30<br />
6         10/9/2011             10/11/2011            Bname      Abc2            20<br />
7         10/8/2011             10/9/2011              Bname      Xyz2            30<br />
8         10/7/2011             10/8/2011              Bname      Xyz2            20<br />
9         10/5/2011             10/7/2011              Bname      Abc2           20<br />
10         10/4/2011             10/5/2011             Bname     Xyz2           30</p>
<p>I do not have primary key on my Table.</p>
<p>If you see the number of rows have been reduced.</p>
<p> I have more than 500 million records and by filtering this I would significantly the number of records in the table.</p>
<p>Is there any efficient query or sproc to do this, if so could you please help me.</p>
<p>I have tried using group by , partitions, ranking but nothing worked .</p>
<p>Thanks &amp; Regards,</p>
<p>VPandit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Riketa Salariya</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-174603</link>
		<dc:creator><![CDATA[Riketa Salariya]]></dc:creator>
		<pubDate>Mon, 03 Oct 2011 11:58:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-174603</guid>
		<description><![CDATA[Thanks

Riketa Salariya &amp; Dhiresh jawale]]></description>
		<content:encoded><![CDATA[<p>Thanks</p>
<p>Riketa Salariya &amp; Dhiresh jawale</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suvasish</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-170521</link>
		<dc:creator><![CDATA[Suvasish]]></dc:creator>
		<pubDate>Thu, 22 Sep 2011 03:26:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-170521</guid>
		<description><![CDATA[Hi Vamshi,

Simply you rock..]]></description>
		<content:encoded><![CDATA[<p>Hi Vamshi,</p>
<p>Simply you rock..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: josekutty varghese</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-168994</link>
		<dc:creator><![CDATA[josekutty varghese]]></dc:creator>
		<pubDate>Sat, 17 Sep 2011 09:29:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-168994</guid>
		<description><![CDATA[Dear Pinal,

     Select Distinct Row_Number() Over (Order By CandidateM.CanID Asc)As    SlNo, CanCode,CanName from CandidateM Where CandidateM.CanCode like &#039;09%&#039;
   Using this query how can I take rownumber of a distinct record....?
   regards,

   josekutty varghese]]></description>
		<content:encoded><![CDATA[<p>Dear Pinal,</p>
<p>     Select Distinct Row_Number() Over (Order By CandidateM.CanID Asc)As    SlNo, CanCode,CanName from CandidateM Where CandidateM.CanCode like &#8217;09%&#8217;<br />
   Using this query how can I take rownumber of a distinct record&#8230;.?<br />
   regards,</p>
<p>   josekutty varghese</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rakesh Kumar Rautray</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-165900</link>
		<dc:creator><![CDATA[Rakesh Kumar Rautray]]></dc:creator>
		<pubDate>Tue, 06 Sep 2011 07:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-165900</guid>
		<description><![CDATA[delete from [BankMaster] where [BankID] in 
(
select [BankID] from (select [BankID], row_number() over(partition by [Bank Name] order by [BankID])RNK from [BankMaster]) BankMaster
where RNK &gt; 1
)]]></description>
		<content:encoded><![CDATA[<p>delete from [BankMaster] where [BankID] in<br />
(<br />
select [BankID] from (select [BankID], row_number() over(partition by [Bank Name] order by [BankID])RNK from [BankMaster]) BankMaster<br />
where RNK &gt; 1<br />
)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-162184</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 26 Aug 2011 09:50:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-162184</guid>
		<description><![CDATA[This will be slower for large table. Use other set based methods like point 6 specified here
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx]]></description>
		<content:encoded><![CDATA[<p>This will be slower for large table. Use other set based methods like point 6 specified here<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikhildas</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-162094</link>
		<dc:creator><![CDATA[Nikhildas]]></dc:creator>
		<pubDate>Fri, 26 Aug 2011 06:12:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-162094</guid>
		<description><![CDATA[CREATE TABLE [dbo].[BankMaster](
	[BankID] [int] NOT NULL,
	[Bank Name] [nvarchar](50) NOT NULL,
	[Address] [nvarchar](max) NULL,
 CONSTRAINT [PK_BankMaster] PRIMARY KEY CLUSTERED 
(
	[BankID] ASC
)
)

INSERT INTO BankMaster
VALUES 
(1,&#039;ING Vysya&#039;,&#039;ING Vysya Eranamkulam&#039;),
(2,&#039;SBT&#039;,&#039;SBT Eranamkulam&#039;),
(3,&#039;Federal&#039;,&#039;Federal Bank Eranamkulam&#039;),
(4,&#039;Canara&#039;,&#039;Canara Eranamkulam&#039;),
(5,&#039;ING Vysya&#039;,&#039;ING Vysya Eranamkulam&#039;),
(6,&#039;SIB&#039;,&#039;SIB Eranamkulam&#039;),
(7,&#039;SBT&#039;,&#039;SBT Eranamkulam&#039;),
(8,&#039;Canara&#039;,&#039;Canara Eranamkulam&#039;),
(9,&#039;ING Vysya&#039;,&#039;ING Vysya Eranamkulam&#039;),
(10,&#039;SBI&#039;,&#039;SBI Eranamkulam&#039;)

DECLARE @BankName NVARCHAR(50),@Cnt INT

DECLARE Cursor_Bank CURSOR LOCAL FAST_FORWARD READ_ONLY FOR
	SELECT BankName,COUNT(BankName) - 1 from BankMaster
	GROUP BY BankName HAVING COUNT(BankName) &gt; 1
OPEN Cursor_Bank
FETCH NEXT FROM Cursor_Bank INTO @bankname,@Cnt
WHILE (@@FETCH_STATUS = 0)
BEGIN
	SET ROWCOUNT @Cnt
	DELETE FROM BankMaster WHERE BankName like @bankname
	SET ROWCOUNT 0
FETCH NEXT FROM Cursor_Bank INTO @bankname,@Cnt	
END
CLOSE Cursor_Bank
DEALLOCATE Cursor_Bank]]></description>
		<content:encoded><![CDATA[<p>CREATE TABLE [dbo].[BankMaster](<br />
	[BankID] [int] NOT NULL,<br />
	[Bank Name] [nvarchar](50) NOT NULL,<br />
	[Address] [nvarchar](max) NULL,<br />
 CONSTRAINT [PK_BankMaster] PRIMARY KEY CLUSTERED<br />
(<br />
	[BankID] ASC<br />
)<br />
)</p>
<p>INSERT INTO BankMaster<br />
VALUES<br />
(1,&#8217;ING Vysya&#8217;,'ING Vysya Eranamkulam&#8217;),<br />
(2,&#8217;SBT&#8217;,'SBT Eranamkulam&#8217;),<br />
(3,&#8217;Federal&#8217;,'Federal Bank Eranamkulam&#8217;),<br />
(4,&#8217;Canara&#8217;,'Canara Eranamkulam&#8217;),<br />
(5,&#8217;ING Vysya&#8217;,'ING Vysya Eranamkulam&#8217;),<br />
(6,&#8217;SIB&#8217;,'SIB Eranamkulam&#8217;),<br />
(7,&#8217;SBT&#8217;,'SBT Eranamkulam&#8217;),<br />
(8,&#8217;Canara&#8217;,'Canara Eranamkulam&#8217;),<br />
(9,&#8217;ING Vysya&#8217;,'ING Vysya Eranamkulam&#8217;),<br />
(10,&#8217;SBI&#8217;,'SBI Eranamkulam&#8217;)</p>
<p>DECLARE @BankName NVARCHAR(50),@Cnt INT</p>
<p>DECLARE Cursor_Bank CURSOR LOCAL FAST_FORWARD READ_ONLY FOR<br />
	SELECT BankName,COUNT(BankName) &#8211; 1 from BankMaster<br />
	GROUP BY BankName HAVING COUNT(BankName) &gt; 1<br />
OPEN Cursor_Bank<br />
FETCH NEXT FROM Cursor_Bank INTO @bankname,@Cnt<br />
WHILE (@@FETCH_STATUS = 0)<br />
BEGIN<br />
	SET ROWCOUNT @Cnt<br />
	DELETE FROM BankMaster WHERE BankName like @bankname<br />
	SET ROWCOUNT 0<br />
FETCH NEXT FROM Cursor_Bank INTO @bankname,@Cnt<br />
END<br />
CLOSE Cursor_Bank<br />
DEALLOCATE Cursor_Bank</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158779</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 11:13:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158779</guid>
		<description><![CDATA[That is the point of this post. That is why it is used to keep only one row for each combination of columns]]></description>
		<content:encoded><![CDATA[<p>That is the point of this post. That is why it is used to keep only one row for each combination of columns</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan Mohapatra</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158725</link>
		<dc:creator><![CDATA[Ivan Mohapatra]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 07:06:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158725</guid>
		<description><![CDATA[Dear pinal,

If i am wrong then correct me.
As per identity column  in a table u will never have a duplicate rows in a table 
because it  grows as 1,2,3,4,5 
so,we can&#039;nt have duplicate rows in a identity column.
but,we can have duplicate data in other column of a identity tables.]]></description>
		<content:encoded><![CDATA[<p>Dear pinal,</p>
<p>If i am wrong then correct me.<br />
As per identity column  in a table u will never have a duplicate rows in a table<br />
because it  grows as 1,2,3,4,5<br />
so,we can&#8217;nt have duplicate rows in a identity column.<br />
but,we can have duplicate data in other column of a identity tables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158724</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 07:03:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158724</guid>
		<description><![CDATA[If there are duplicates in columns DuplicateColumn1, DuplicateColumn2, DuplicateColumn3 then the code will delete all related rows but keep the row with maximum id]]></description>
		<content:encoded><![CDATA[<p>If there are duplicates in columns DuplicateColumn1, DuplicateColumn2, DuplicateColumn3 then the code will delete all related rows but keep the row with maximum id</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158722</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 07:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158722</guid>
		<description><![CDATA[select t1.* from customer as t1 inner join
(
SELECT firstname,surname,count(*)
FROM customer
group by firstname,surname
having count(*) &gt; 1
) as t2 on t1.firstname=t2.firstname and t1.surname=t2.surname]]></description>
		<content:encoded><![CDATA[<p>select t1.* from customer as t1 inner join<br />
(<br />
SELECT firstname,surname,count(*)<br />
FROM customer<br />
group by firstname,surname<br />
having count(*) &gt; 1<br />
) as t2 on t1.firstname=t2.firstname and t1.surname=t2.surname</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158721</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 06:58:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158721</guid>
		<description><![CDATA[Refer method 6
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx]]></description>
		<content:encoded><![CDATA[<p>Refer method 6<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158720</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 06:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158720</guid>
		<description><![CDATA[This will be very ineffecient for large table. You can use other methods like point 6 here
http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx]]></description>
		<content:encoded><![CDATA[<p>This will be very ineffecient for large table. You can use other methods like point 6 here<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rojo</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-158706</link>
		<dc:creator><![CDATA[Rojo]]></dc:creator>
		<pubDate>Thu, 18 Aug 2011 06:06:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-158706</guid>
		<description><![CDATA[Hi, 

Find another method using loop.

Consider the table #temp as below,
Id          Value
------------------
1	100
2	200
2	200
3	300
3	300
3	300

DECLARE @Cnt INT
SET @Cnt = 1

WHILE @Cnt IS NOT NULL
BEGIN
	SELECT TOP 1 @Cnt = COUNT(Id) FROM #Test
		GROUP BY Id,Value
		HAVING COUNT(Id) &gt; 1
		ORDER BY Id,Value
	
	IF @Cnt IS NULL OR @Cnt = 1 RETURN

	SET @Cnt = @Cnt-1
	SET ROWCOUNT @Cnt

	DELETE t1
	FROM #Test t1
	JOIN
		(SELECT TOP 1 Id,Value,COUNT(Id) Cnt FROM #Test
		GROUP BY Id,Value
		HAVING COUNT(Id) &gt; 1
		ORDER BY Id,Value) t2 ON t2.Id = t1.Id AND t2.Value = t1.Value

	SET ROWCOUNT 0
END]]></description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>Find another method using loop.</p>
<p>Consider the table #temp as below,<br />
Id          Value<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
1	100<br />
2	200<br />
2	200<br />
3	300<br />
3	300<br />
3	300</p>
<p>DECLARE @Cnt INT<br />
SET @Cnt = 1</p>
<p>WHILE @Cnt IS NOT NULL<br />
BEGIN<br />
	SELECT TOP 1 @Cnt = COUNT(Id) FROM #Test<br />
		GROUP BY Id,Value<br />
		HAVING COUNT(Id) &gt; 1<br />
		ORDER BY Id,Value</p>
<p>	IF @Cnt IS NULL OR @Cnt = 1 RETURN</p>
<p>	SET @Cnt = @Cnt-1<br />
	SET ROWCOUNT @Cnt</p>
<p>	DELETE t1<br />
	FROM #Test t1<br />
	JOIN<br />
		(SELECT TOP 1 Id,Value,COUNT(Id) Cnt FROM #Test<br />
		GROUP BY Id,Value<br />
		HAVING COUNT(Id) &gt; 1<br />
		ORDER BY Id,Value) t2 ON t2.Id = t1.Id AND t2.Value = t1.Value</p>
<p>	SET ROWCOUNT 0<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajesh</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-156199</link>
		<dc:creator><![CDATA[Rajesh]]></dc:creator>
		<pubDate>Thu, 11 Aug 2011 15:18:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-156199</guid>
		<description><![CDATA[Hi,pinal,

when we handling a large database like 10GB size of records.

how can i find duplicates and delete that duplicates.

finding duplicate is not a problem but how to remove those duplicates ?

Please suggest me.

Thank u!]]></description>
		<content:encoded><![CDATA[<p>Hi,pinal,</p>
<p>when we handling a large database like 10GB size of records.</p>
<p>how can i find duplicates and delete that duplicates.</p>
<p>finding duplicate is not a problem but how to remove those duplicates ?</p>
<p>Please suggest me.</p>
<p>Thank u!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajeshkumar</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-153101</link>
		<dc:creator><![CDATA[Rajeshkumar]]></dc:creator>
		<pubDate>Wed, 03 Aug 2011 10:18:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-153101</guid>
		<description><![CDATA[Nice code.I learn much more from your code]]></description>
		<content:encoded><![CDATA[<p>Nice code.I learn much more from your code</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/#comment-146168</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 05 Jul 2011 14:30:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/03/01/delete-duplicate-records/#comment-146168</guid>
		<description><![CDATA[You dont need to use a cursor for this. Refer point 6 at http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx]]></description>
		<content:encoded><![CDATA[<p>You dont need to use a cursor for this. Refer point 6 at <a href="http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

