Re: Update from join - Mailing list pgsql-sql

From Gary Stainburn
Subject Re: Update from join
Date
Msg-id 200607071239.31808.gary.stainburn@ringways.co.uk
Whole thread Raw
In response to Update from join  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
List pgsql-sql
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     


pgsql-sql by date:

Previous
From: "D'Arcy J.M. Cain"
Date:
Subject: Re: Alternative to serial primary key
Next
From: Michael Glaesemann
Date:
Subject: Re: Update from join