<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>duplicate rows &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/duplicate-rows/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Thu, 14 Sep 2017 11:44:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>Delete all duplicates rows except one in SQL Server</title>
		<link>https://www.dbrnd.com/2015/09/delete-all-duplicates-rows-in-sql-server/</link>
					<comments>https://www.dbrnd.com/2015/09/delete-all-duplicates-rows-in-sql-server/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 14 Sep 2015 18:00:31 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[duplicate rows]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=575</guid>

					<description><![CDATA[In this post, I am sharing two different SQL scripts to delete the all duplicate rows except the one in SQL Server. Before a few days ago, I was working on a production report and found duplicates records in the few tables. I worked around this and created the different solutions for removing all duplicate [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&amp;linkname=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&amp;linkname=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&amp;linkname=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&amp;linkname=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&amp;linkname=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&amp;linkname=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fdelete-all-duplicates-rows-in-sql-server%2F&#038;title=Delete%20all%20duplicates%20rows%20except%20one%20in%20SQL%20Server" data-a2a-url="https://www.dbrnd.com/2015/09/delete-all-duplicates-rows-in-sql-server/" data-a2a-title="Delete all duplicates rows except one in SQL Server"></a></p><h4>In this post, I am sharing two different SQL scripts to delete the all duplicate rows except the one in SQL Server.</h4>
<p>Before a few days ago, I was working on a production report and found duplicates records in the few tables. I worked around this and created the different solutions for removing all duplicate rows.</p>
<p><strong>Let&#8217;s first create a sample table and data:<br />
</strong><br />
<pre class="crayon-plain-tag">CREATE TABLE tbl_RemoveDuplicate
(	
	ID INTEGER PRIMARY KEY
	,Name VARCHAR(150)
)
GO

INSERT INTO tbl_RemoveDuplicate VALUES
(1,'ABC'),(2,'XYZ')
,(3,'XYZ'),(4,'RFQ')
,(5,'PQR'),(6,'EFG')
,(7,'EFG'),(8,'ABC')
GO</pre>
<p><strong>First solution is using WITH CTE:</strong><br />
<pre class="crayon-plain-tag">;WITH cteDuplicate AS 
(
    SELECT 
       Name
       ,ROW_NUMBER() OVER (PARTITION BY Name ORDER BY Name) RowNumber
    FROM  tbl_RemoveDuplicate
)
DELETE FROM cteDuplicate
WHERE RowNumber &gt; 1
GO</pre>
<p><strong>Second solution is using SELF JOIN:</strong><br />
<pre class="crayon-plain-tag">DELETE FROM A
FROM tbl_RemoveDuplicate AS A
INNER JOIN tbl_RemoveDuplicate AS B
  ON A.Name = B.Name AND A.ID &gt; B.ID
GO</pre>
<p><strong>Check your table after remove the duplicates:</strong><br />
<pre class="crayon-plain-tag">SELECT *FROM tbl_RemoveDuplicate ORDER BY ID

--Result:

ID          Name
----------- ------------
1           ABC
2           XYZ
4           RFQ
5           PQR
6           EFG

(5 row(s) affected)</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/09/delete-all-duplicates-rows-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
