<?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>subquery &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/subquery/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>Wed, 11 Oct 2017 06:41:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>PostgreSQL: Update the Table data using Subquery</title>
		<link>https://www.dbrnd.com/2016/03/postgresql-update-the-table-data-using-subquery/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 19 Mar 2016 21:03:58 +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[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[subquery]]></category>
		<category><![CDATA[UPDATE]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1910</guid>

					<description><![CDATA[In this post, I am going to share a demonstration on how to update the table data using a Subquery in the PostgreSQL. This is a fundamental help, but I found that most of the beginners always try to find the script for Subquery or Joins. Below is a small demonstration: Create two sample tables [&#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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" 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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" 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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" 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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" 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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" 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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&amp;linkname=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" 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%2F2016%2F03%2Fpostgresql-update-the-table-data-using-subquery%2F&#038;title=PostgreSQL%3A%20Update%20the%20Table%20data%20using%20Subquery" data-a2a-url="https://www.dbrnd.com/2016/03/postgresql-update-the-table-data-using-subquery/" data-a2a-title="PostgreSQL: Update the Table data using Subquery"></a></p><p>In this post, I am going to share a demonstration on how to update the table data using a Subquery in the PostgreSQL.</p>
<p>This is a fundamental help, but I found that most of the beginners always try to find the script for  Subquery or Joins.</p>
<p><strong>Below is a small demonstration:</strong></p>
<p><strong>Create two sample tables for Employee:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_EmployeeDetails 
(
	EmpID SERIAL PRIMARY KEY
	,EmpName CHARACTER VARYING(50)
	,TotalPerformanceCount INTEGER DEFAULT 0
);

CREATE TABLE tbl_EmployeePerformanceCounter
(
	PerformanceCounterID SERIAL PRIMARY KEY
	,EmpID INTEGER
	,PerformanceCounter INTEGER
	,RecordDateTime TIMESTAMP WITHOUT TIME ZONE
	,CONSTRAINT fk_tbl_EmployeePerformanceCounter_EmpID 
         FOREIGN KEY (EmpID) REFERENCES tbl_EmployeeDetails(EmpID)
);</pre><p>
<p><strong>Insert sample data into both the tables:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_EmployeeDetails (EmpName)
VALUES ('Anvesh'),('Neevan'),('Martin'),('Roy'),('Jenny');

INSERT INTO tbl_EmployeePerformanceCounter
(EmpID,PerformanceCounter,RecordDateTime)
VALUES
(1,300,'20150101')
,(1,100,'20150201')
,(1,200,'20150301')
,(2,140,'20150101')
,(2,320,'20150201')
,(3,120,'20150101')
,(3,150,'20150201')
,(4,150,'20150101')
,(4,200,'20150201')
,(4,100,'20150301');</pre><p>
<p><strong>Update the count of the employee performance counter using Subquery:</strong></p><pre class="crayon-plain-tag">UPDATE tbl_EmployeeDetails
SET TotalPerformanceCount=T.TotalCount   
FROM (SELECT EmpID,SUM(PerformanceCounter) AS TotalCount
      FROM tbl_EmployeePerformanceCounter GROUP BY EmpID) AS T
WHERE tbl_EmployeeDetails.EmpID=T.EmpID;</pre><p>
<p><strong>The Result:</strong></p><pre class="crayon-plain-tag">SELECT *FROM tbl_EmployeeDetails ORDER BY 1;</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateDataUsingSubquery.png" rel="attachment wp-att-1912"><img decoding="async" class="alignnone wp-image-1912 size-full" title="PostgreSQL Update Data Using Subquery" src="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateDataUsingSubquery.png" alt="PostgreSQL Update Data Using Subquery" width="322" height="128" srcset="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateDataUsingSubquery.png 322w, https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateDataUsingSubquery-300x119.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUpdateDataUsingSubquery-150x60.png 150w" sizes="(max-width: 322px) 100vw, 322px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
