pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Updating a table from another table
2+ messages / 2 participants
[nested] [flat]

* Updating a table from another table
@ 2002-06-04 20:37  Matthew Price <pricem@juno.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Matthew Price @ 2002-06-04 20:37 UTC (permalink / raw)
  To: pgsql-sql

Howdy All,

I need to update many records in one table with data from another table that ultimately gets \copy-ed from an outside source.

customers:
custnum varchar(6),
name text,
canceldate date
...

cancels:
custnum varchar(6),
canceldate date


What is the right way to update the canceldate in the customers table from canceldate in the cancels table?  Is there a way to use update to iterate rather than making a mass change?

Thanks in advance,
Matthew




________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
http://dl.www.juno.com/get/web/.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Updating a table from another table
@ 2002-06-04 21:38  Jean-Luc Lachance <jllachan@nsd.ca>
  parent: Matthew Price <pricem@juno.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Jean-Luc Lachance @ 2002-06-04 21:38 UTC (permalink / raw)
  To: Matthew Price <pricem@juno.com>; +Cc: pgsql-sql

Try:

UPDATE customers
SET canceldate = cancels.canceldate
FROM cancels
WHERE customers.custnum = cancels.custnum;

You should also have an index on cancels(custnum).

JLL



Matthew Price wrote:
> 
> Howdy All,
> 
> I need to update many records in one table with data from another table that ultimately gets \copy-ed from an outside source.
> 
> customers:
> custnum varchar(6),
> name text,
> canceldate date
> ...
> 
> cancels:
> custnum varchar(6),
> canceldate date
> 
> What is the right way to update the canceldate in the customers table from canceldate in the cancels table?  Is there a way to use update to iterate rather than making a mass change?
> 
> Thanks in advance,
> Matthew
> 
> ________________________________________________________________
> GET INTERNET ACCESS FROM JUNO!
> Juno offers FREE or PREMIUM Internet access for less!
> Join Juno today!  For your FREE software, visit:
> http://dl.www.juno.com/get/web/.
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-06-04 21:38 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-06-04 20:37 Updating a table from another table Matthew Price <pricem@juno.com>
2002-06-04 21:38 ` Jean-Luc Lachance <jllachan@nsd.ca>

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