X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 966D1D1B549 for ; Wed, 29 Oct 2003 14:59:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 36345-06 for ; Wed, 29 Oct 2003 10:58:58 -0400 (AST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id C6C43D1B538 for ; Wed, 29 Oct 2003 10:58:54 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id AA6B834FF1; Wed, 29 Oct 2003 06:58:42 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id A909034FE1; Wed, 29 Oct 2003 06:58:42 -0800 (PST) Date: Wed, 29 Oct 2003 06:58:42 -0800 (PST) From: Stephan Szabo To: Gary Stainburn Cc: pgsql-sql@postgresql.org Subject: Re: update from select In-Reply-To: <200310290911.54453.gary.stainburn@ringways.co.uk> Message-ID: <20031029065413.C97497@megazone.bigpanda.com> References: <200310290911.54453.gary.stainburn@ringways.co.uk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/382 X-Sequence-Number: 15782 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?