X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 1C0119FB1C7 for ; Fri, 7 Jul 2006 08:40:49 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 18420-02-2 for ; Fri, 7 Jul 2006 08:40:44 -0300 (ADT) X-Greylist: delayed 01:09:52.358175 by SQLgrey- Received: from mail.ringways.co.uk (host-80-193-83-141.static.telewest.net [80.193.83.141]) by postgresql.org (Postfix) with ESMTP id 3DCF89FB218 for ; Fri, 7 Jul 2006 08:40:43 -0300 (ADT) Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.62) (envelope-from ) id 1FyogH-0002B4-EE for pgsql-sql@postgresql.org; Fri, 07 Jul 2006 12:39:33 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: Update from join Date: Fri, 7 Jul 2006 12:39:31 +0100 User-Agent: KMail/1.9.1 References: <200607071129.35291.gary.stainburn@ringways.co.uk> In-Reply-To: <200607071129.35291.gary.stainburn@ringways.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200607071239.31808.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/91 X-Sequence-Number: 25665 On Friday 07 July 2006 11:29, Gary Stainburn wrote: > I know this is probably a FAQ but Google etc hasn't helped. > > I have two tables, both with stock number and registration number in. > The second table always has the correct stock number, the first doesn't. > > I want to copy the data across where the stock number is missing. The > select with join shows the rows requiring update, but I can't think how to > do the update. > I came up with: goole=# update test1 set ud_stock=(select s_stock_no from test2 where test1.ud_registration = test2.s_regno) where ud_stock ~ '^[NU][LD]$'; UPDATE 679 but as you can see, it updated a hell of a lot more than 21 rows. Can anyone improve on this? Gary -- 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