X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 74E8AD1B44E for ; Sat, 3 Jan 2004 09:21:49 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 50030-02 for ; Sat, 3 Jan 2004 05:21:02 -0400 (AST) Received: from ms-smtp-02-eri0.ohiordc.rr.com (ms-smtp-02-smtplb.ohiordc.rr.com [65.24.5.136]) by svr1.postgresql.org (Postfix) with ESMTP id 99F01D1B443 for ; Sat, 3 Jan 2004 05:20:56 -0400 (AST) Received: from coryat.com (cpe-066-061-083-103.midsouth.rr.com [66.61.83.103]) by ms-smtp-02-eri0.ohiordc.rr.com (8.12.10/8.12.7) with ESMTP id i039KnaZ027311 for ; Sat, 3 Jan 2004 04:20:50 -0500 (EST) Message-ID: <3FF6896E.3010602@coryat.com> Date: Sat, 03 Jan 2004 03:20:46 -0600 From: John Coryat User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.5) Gecko/20030925 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Complex Update Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/22 X-Sequence-Number: 16415 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?