X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9471856471 for ; Mon, 7 Mar 2005 14:51:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80173-02 for ; Mon, 7 Mar 2005 14:51:31 +0000 (GMT) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by svr1.postgresql.org (Postfix) with ESMTP id B465356460 for ; Mon, 7 Mar 2005 14:51:29 +0000 (GMT) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 1D8JUl-00031W-00 for pgsql-sql@postgresql.org; Mon, 07 Mar 2005 14:46:07 +0000 Content-Type: text/plain; charset="iso-8859-1" From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: simple update from select ?? Date: Mon, 7 Mar 2005 14:44:31 +0000 User-Agent: KMail/1.4.3 References: <200503071228.39699.gary.stainburn@ringways.co.uk> In-Reply-To: <200503071228.39699.gary.stainburn@ringways.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200503071430.15405.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200503/103 X-Sequence-Number: 20582 On Monday 07 March 2005 12:28 pm, you wrote: > Hi folks > > I've got a table of pieces of equipment. > One piece of equipment may be owned by another piece of equipment, > and may own multiple other pieces. > > To hold the relationship I have a piece_pieces table holding the > owner (pp_id) part id and the owned part ids (pp_part). > > I'v realised I can store this within the original table so I've added > an owner attribute. I need to now populate this now from the other > table, but I can't work out how. > > I've got pieces table > > p_id -- part id > p_owner -- new owner attribute > > piece_pieces table > > pp_id -- id of owner > pp_part -- id of owned For my own future reference as much as anything, here's the required statement, which is a syntactically corrected version of a suggestion by Sean Davis update pieces set p_owner=piece_pieces.pp_id from piece_pieces where piece_pieces.pp_part=pieces.p_id; Under Sean's suggestion I did this inside a transaction block so I could check that it did what I wanted. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000