Re: update from select

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: update from select
Date: 2003-10-29 14:58:42
Message-ID: 20031029065413.C97497@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 29 Oct 2003, Gary Stainburn wrote:

> Hi folks,
>
> don't know if it's cos of the 17 hours I've just worked (sympathy vote please)
> but I can't get this one worked out
>
> I've got table names with nid as name id field and nallowfollow flag.
> I've got a vehicles table with vowner pointing at nid and a vallowfollow
> field.
>
> How can I update nallowfollow from the appropriate vallowfollow flag?

If vehicles.vowner is unique, something like this maybe (using extensions
to sql)?
update names set nallowfollow=vehicles.vallowfollow
from vehicles where vehicles.vowner=names.nid;

I think it'd be the follwoing in straight sql:
update names set nallowfollow=
(select vallowfollow from vehicles where vehicles.vowner=names.nid);

If it's not unique, what do you do if there are two vehicles with the same
vowner and different values for vallowfollow?

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message OpenGis 2003-10-29 15:03:15 Re: Link Oracle tables in Postgre
Previous Message Jeff Kowalczyk 2003-10-29 14:52:52 Help on update that subselects other records in table, uses joins