pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: Update from join
Date: Fri, 7 Jul 2006 12:39:31 +0100
Message-ID: <200607071239.31808.gary.stainburn@ringways.co.uk> (raw)
In-Reply-To: <200607071129.35291.gary.stainburn@ringways.co.uk>
References: <200607071129.35291.gary.stainburn@ringways.co.uk>

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     



view thread (5+ messages)  latest in thread

Message-ID: <200607071239.31808.gary.stainburn@ringways.co.uk>
Permalink:  ../200607071239.31808.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/200607071239.31808.gary.stainburn@ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: Update from join
  In-Reply-To: <200607071239.31808.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox