pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Update query by joining multiple tables.
3+ messages / 3 participants
[nested] [flat]

* Update query by joining multiple tables.
@ 2007-01-17 11:20  Moiz Kothari <moizpostgres@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Moiz Kothari @ 2007-01-17 11:20 UTC (permalink / raw)
  To: pgsql-sql

Guys,

on page this

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
tried and it worked just fine for me. Something like this :

Infact update can work between multiple tables to... do something like :

UPDATE employees SET sales_count = a.sales_count FROM accounts as a
  WHERE a.name = 'Acme Corporation'
  AND employees.id = a.sales_person;

considering sales_count as a column in accounts table.

Regards,
Moiz

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Update query by joining multiple tables.
@ 2007-01-17 12:55  Andrew Sullivan <ajs@crankycanuck.ca>
  parent: Moiz Kothari <moizpostgres@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Andrew Sullivan @ 2007-01-17 12:55 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Update query by joining multiple tables.
@ 2007-01-17 15:01  Shoaib Mir <shoaibmir@gmail.com>
  parent: Andrew Sullivan <ajs@crankycanuck.ca>
  0 siblings, 0 replies; 3+ messages in thread

From: Shoaib Mir @ 2007-01-17 15:01 UTC (permalink / raw)
  To: Andrew Sullivan <ajs@crankycanuck.ca>; +Cc: pgsql-sql

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
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-01-17 15:01 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-01-17 11:20 Update query by joining multiple tables. Moiz Kothari <moizpostgres@gmail.com>
2007-01-17 12:55 ` Andrew Sullivan <ajs@crankycanuck.ca>
2007-01-17 15:01   ` Shoaib Mir <shoaibmir@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox