From: | Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Update from join |
Date: | 2006-07-07 11:39:31 |
Message-ID: | 200607071239.31808.gary.stainburn@ringways.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2006-07-07 11:54:42 | Re: Alternative to serial primary key |
Previous Message | D'Arcy J.M. Cain | 2006-07-07 11:33:25 | Re: Alternative to serial primary key |