pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: John Coryat <john@coryat.com>
To: pgsql-sql@postgresql.org
Subject: Re: Complex Update
Date: Mon, 5 Jan 2004 11:10:30 +0000
Message-ID: <200401051110.30065.dev@archonet.com> (raw)
In-Reply-To: <3FF6896E.3010602@coryat.com>
References: <3FF6896E.3010602@coryat.com>

On Saturday 03 January 2004 09:20, John Coryat wrote:
> Problem: I have a table that has a field I want to plug with a value
> from other tables.
[snip]
> I would expect it to look something like this:
>
> update orderheader set total = (select sum(amount) from orderdetail
> where orderdetail.orderno=orderheader.orderno) ;

Looks fine to me. In general, you can do something of the form:

UPDATE ta SET a2 = (SELECT expr(b2) FROM tb WHERE b1=a1);

NOTE - make sure you understand what happens when there is no b1=a1 and what 
that will mean to your particular setup.

-- 
  Richard Huxton
  Archonet Ltd



view thread (2+ messages)

Message-ID: <200401051110.30065.dev@archonet.com>
Permalink:  ../200401051110.30065.dev@archonet.com/
Also on:    postgresql.org/message-id/200401051110.30065.dev@archonet.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: dev@archonet.com, john@coryat.com
  Subject: Re: Complex Update
  In-Reply-To: <200401051110.30065.dev@archonet.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