Re: Complex Update

From: Richard Huxton <dev(at)archonet(dot)com>
To: John Coryat <john(at)coryat(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Complex Update
Date: 2004-01-05 11:10:30
Message-ID: 200401051110.30065.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message teknokrat 2004-01-05 17:14:26 grouping by date
Previous Message Kumar 2004-01-05 11:04:38 Virtual records