Thread: Update query by joining multiple tables.

Update query by joining multiple tables.

From
"Moiz Kothari"
Date:
Guys,<br /><br />on page this<br /><br /><a
href="http://www.postgresql.org/docs/8.1/interactive/sql-update.html">http://www.postgresql.org/docs/8.1/interactive/sql-update.html</a>,
itis not specified if a join can be done between multiple tables to update a table, i tried and it worked just fine for
me.Something like this : <br /><br />Infact update can work between multiple tables to... do something like :<br /><br
/>UPDATEemployees SET sales_count = a.sales_count FROM accounts as a<br />  WHERE <a href="http://a.name">a.name</a> =
'AcmeCorporation' <br />  AND <a href="http://employees.id">employees.id</a> = a.sales_person;<br /><br />considering
sales_countas a column in accounts table.<br /><br />Regards,<br />Moiz<br /><br /><br /> 

Re: Update query by joining multiple tables.

From
Andrew Sullivan
Date:
On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote:
> http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not
> specified if a join can be done between multiple tables to update a table, i

Sure it is:

A list of table expressions, allowing columns from other tables to
appear in the WHERE condition and the update expressions.

a

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
Users never remark, "Wow, this software may be buggy and hard 
to use, but at least there is a lot of code underneath."    --Damien Katz


Re: Update query by joining multiple tables.

From
"Shoaib Mir"
Date:
Might be a view and then a rule attached with that can help you out with doing updates using joins

--------------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 1/17/07, Andrew Sullivan <ajs@crankycanuck.ca> wrote:
On Wed, Jan 17, 2007 at 04:50:18PM +0530, Moiz Kothari wrote:
> http://www.postgresql.org/docs/8.1/interactive/sql-update.html, it is not
> specified if a join can be done between multiple tables to update a table, i

Sure it is:

A list of table expressions, allowing columns from other tables to
appear in the WHERE condition and the update expressions.

a

--
Andrew Sullivan  | ajs@crankycanuck.ca
Users never remark, "Wow, this software may be buggy and hard
to use, but at least there is a lot of code underneath."
                --Damien Katz

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match