pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Coryat <john@coryat.com>
To: pgsql-sql@postgresql.org
Subject: Complex Update
Date: Sat, 03 Jan 2004 03:20:46 -0600
Message-ID: <3FF6896E.3010602@coryat.com> (raw)

Problem: I have a table that has a field I want to plug with a value 
from other tables.

I can do it with a perl program and a loop, but want to do it with a 
single SQL statement.

Is there a way to do an update that combines a select statement 
containing a "where" that uses a field from the row to be updated?

I would expect it to look something like this:

update orderheader set total = (select sum(amount) from orderdetail 
where orderdetail.orderno=orderheader.orderno) ;

Any ideas?




view thread (2+ messages)  latest in thread

Message-ID: <3FF6896E.3010602@coryat.com>
Permalink:  ../3FF6896E.3010602@coryat.com/
Also on:    postgresql.org/message-id/3FF6896E.3010602@coryat.com

 · 

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: john@coryat.com
  Subject: Re: Complex Update
  In-Reply-To: <3FF6896E.3010602@coryat.com>

* 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