<?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>records &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/records/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, 17 Sep 2019 19:49: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>PostgreSQL: How to Delete all duplicate rows Except one</title>
		<link>https://www.dbrnd.com/2019/09/postgresql-how-to-delete-all-duplicate-rows-except-one/</link>
					<comments>https://www.dbrnd.com/2019/09/postgresql-how-to-delete-all-duplicate-rows-except-one/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 17 Sep 2019 19:49:01 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[delete duplicate]]></category>
		<category><![CDATA[duplicate record]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[records]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3837</guid>

					<description><![CDATA[I have already written a similar article to delete duplicate records in SQL Server and MySQL. Here, You can also access that articles. Delete all duplicate rows in MySQL Delete all duplicates rows except one in SQL Server Recently, I got one request for one script to delete duplicate records in PostgreSQL. Most of the [&#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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" 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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" 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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" 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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" 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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" 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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" 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%2F2019%2F09%2Fpostgresql-how-to-delete-all-duplicate-rows-except-one%2F&#038;title=PostgreSQL%3A%20How%20to%20Delete%20all%20duplicate%20rows%20Except%20one" data-a2a-url="https://www.dbrnd.com/2019/09/postgresql-how-to-delete-all-duplicate-rows-except-one/" data-a2a-title="PostgreSQL: How to Delete all duplicate rows Except one"></a></p><p>I have already written a similar article to delete duplicate records in SQL Server and MySQL.<br />
Here, You can also access that articles. </p>
<blockquote class="wp-embedded-content" data-secret="4BibnBnPRG"><p><a href="https://www.dbrnd.com/2015/09/delete-all-duplicate-rows-in-mysql/">Delete all duplicate rows in MySQL</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/09/delete-all-duplicate-rows-in-mysql/embed/#?secret=4BibnBnPRG" data-secret="4BibnBnPRG" width="600" height="338" title="&#8220;Delete all duplicate rows in MySQL&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="hOr3tlfWTl"><p><a href="https://www.dbrnd.com/2015/09/delete-all-duplicates-rows-in-sql-server/">Delete all duplicates rows except one in SQL Server</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/09/delete-all-duplicates-rows-in-sql-server/embed/#?secret=hOr3tlfWTl" data-secret="hOr3tlfWTl" width="600" height="338" title="&#8220;Delete all duplicates rows except one in SQL Server&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>Recently, I got one request for one script to delete duplicate records in PostgreSQL.<br />
Most of the Database Developers have such a requirement to delete duplicate records from the Database.</p></blockquote>
<blockquote><p>Like SQL Server, ROW_NUMBER() PARTITION BY is also available in PostgreSQL.<br />
I have prepared this script, using simple inner query with the use of ROW_NUMBER() PARTITION BY clause. </p></blockquote>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_RemoveDuplicate
(	
	ID INTEGER PRIMARY KEY
	,Name VARCHAR(150)
);</pre> </p>
<p><strong>Insert few duplicate records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_RemoveDuplicate VALUES
(1,'ABC'),(2,'XYZ')
,(3,'XYZ'),(4,'RFQ')
,(5,'PQR'),(6,'EFG')
,(7,'EFG'),(8,'ABC');</pre> </p>
<p><strong>Except one, Delete all duplicate records:</strong></p>
<pre class="crayon-plain-tag">DELETE FROM tbl_RemoveDuplicate
WHERE ID IN 
(SELECT ID
FROM (SELECT id,
	     ROW_NUMBER() OVER (partition BY Name ORDER BY ID) AS RowNumber
     FROM tbl_RemoveDuplicate) AS T
WHERE T.RowNumber &gt; 1);</pre> </p>
<p><strong>Check the result:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM tbl_RemoveDuplicate;
 id | name
----+------
  1 | ABC
  2 | XYZ
  4 | RFQ
  5 | PQR
  6 | EFG
(5 rows)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/09/postgresql-how-to-delete-all-duplicate-rows-except-one/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
