X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CC80FD91FA for ; Wed, 5 Oct 2005 09:20:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 52235-06 for ; Wed, 5 Oct 2005 12:20:41 +0000 (GMT) Received: from gatefox.foxi.nl (foxi.xs4all.nl [194.109.246.192]) by svr1.postgresql.org (Postfix) with ESMTP id 70A95D9106 for ; Wed, 5 Oct 2005 09:20:40 -0300 (ADT) Received: from techfox.foxi (techfox.foxi [192.168.0.79]) by gatefox.foxi.nl (8.13.3/8.13.3) with ESMTP id j95CLvS5021866; Wed, 5 Oct 2005 14:21:57 +0200 From: Frank van Vugt Organization: Foxi Consultants in Technology BV To: "Joost Kraaijeveld" Subject: Re: Help with simple SQL query? Date: Wed, 5 Oct 2005 14:21:56 +0200 User-Agent: KMail/1.8 References: <71E37EF6B7DCC1499CEA0316A2568328024BBA0B@loki.wc.globexplorer.net> In-Reply-To: <71E37EF6B7DCC1499CEA0316A2568328024BBA0B@loki.wc.globexplorer.net> Cc: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510051421.56840.ftm.van.vugt@foxi.nl> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.067 required=5 tests=[AWL=0.017, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/33 X-Sequence-Number: 22886 Hi Joost, Try joining and comparing the order table with/to an aggregated orderline table, something like this: select order_id, order_price, sum_price, order_price - sum_price as diff from order, (select parent_order_id, sum(orderline_price) as sum_price from orderline group by parent_order_id) as foo where order_id = parent_order_id and order_price != sum_price This should prove to be as efficient as it gets ;) -- Best, Frank.