Complex Update

From: John Coryat <john(at)coryat(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Complex Update
Date: 2004-01-03 09:20:46
Message-ID: 3FF6896E.3010602@coryat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tatsuo Ishii 2004-01-04 13:51:15 DO INSTEAD in rule
Previous Message Adam Ruth 2004-01-03 04:32:51 Re: sort by on two columns