<?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>SQL SQL Query &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sql-sql-query/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>Tue, 21 Nov 2017 05:42:01 +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>Copy unique records from one table to another in SQL Server</title>
		<link>https://www.dbrnd.com/2015/06/copy-unique-records-from-one-table-to-another-sql-server/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 01 Jun 2015 17:39:07 +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[PARTITION BY]]></category>
		<category><![CDATA[ROW_NUMBER]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[SQL SQL Query]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[unique records]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=231</guid>

					<description><![CDATA[In this post, I am sharing a script to copy a unique record from one table to another. You can perform this activity using ROW_NUMBER() and PARTITION BY clause. This partition clause identified set of duplicate records and row_number assign an ID for this set. Below is a full demonstration: Let&#8217;s first create table with [&#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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&amp;linkname=Copy%20unique%20records%20from%20one%20table%20to%20another%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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&amp;linkname=Copy%20unique%20records%20from%20one%20table%20to%20another%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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&amp;linkname=Copy%20unique%20records%20from%20one%20table%20to%20another%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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&amp;linkname=Copy%20unique%20records%20from%20one%20table%20to%20another%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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&amp;linkname=Copy%20unique%20records%20from%20one%20table%20to%20another%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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&amp;linkname=Copy%20unique%20records%20from%20one%20table%20to%20another%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%2F06%2Fcopy-unique-records-from-one-table-to-another-sql-server%2F&#038;title=Copy%20unique%20records%20from%20one%20table%20to%20another%20in%20SQL%20Server" data-a2a-url="https://www.dbrnd.com/2015/06/copy-unique-records-from-one-table-to-another-sql-server/" data-a2a-title="Copy unique records from one table to another in SQL Server"></a></p><p>In this post, I am sharing a script to copy a unique record from one table to another.</p>
<p>You can perform this activity using ROW_NUMBER() and PARTITION BY clause.</p>
<p>This partition clause identified set of duplicate records and row_number assign an ID for this set.</p>
<p>Below is a full demonstration:</p>
<p><strong>Let&#8217;s first create table with some records:</strong></p><pre class="crayon-plain-tag">CREATE TABLE dbo.tbl_First
(
 ID INTEGER IDENTITY(1,1)
 ,Name VARCHAR(250)
)
GO
INSERT INTO dbo.tbl_First(Name) VALUES('ABC'),('XYZ'),('ABC'),('EFG'),('PQR'),('EFG'),('RND'),('YFQ'),('XVK'),('ABC')
GO
SELECT *FROM dbo.tbl_First ORDER BY Name 
GO</pre><p>
<p><strong>Result of above select statement is:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/06/SQLResult1.png"><img decoding="async" class="aligncenter wp-image-232 size-full" title="copy unique record sql server" src="https://www.dbrnd.com/wp-content/uploads/2015/06/SQLResult1.png" alt="copy unique record sql server" width="121" height="241" /></a><b>You can see ABC and EFG are duplicate name.</b></p>
<p><strong>Create a second table with copy unique data from the first table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE dbo.tbl_Second
(
 ID INTEGER 
 ,Name VARCHAR(250)
)
GO
 
INSERT INTO dbo.tbl_Second
SELECT 
 ID
 ,Name   
FROM
(
 SELECT 
  ID
  ,Name
  ,ROW_NUMBER() OVER (PARTITION BY Name ORDER BY ID) AS RowNumber
 FROM  dbo.tbl_First AS T
)AS T WHERE T.RowNumber = 1 
GO

SELECT *FROM dbo.tbl_Second
GO</pre>
<p><strong>The result of above second table is:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/06/SQLResult2.png"><img decoding="async" class="aligncenter wp-image-233 size-full" title="copy unique record sql server" src="https://www.dbrnd.com/wp-content/uploads/2015/06/SQLResult2.png" alt="copy unique record sql server" width="108" height="186" /></a>Now you can see all names are unique and copied only seven unique records.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
