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 43BB3D8CC7 for ; Wed, 5 Oct 2005 08:36:16 -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 65200-08 for ; Wed, 5 Oct 2005 11:36:09 +0000 (GMT) Received: from obelix.askesis.nl (laudanum.demon.nl [82.161.125.16]) by svr1.postgresql.org (Postfix) with ESMTP id 33959D9E4C for ; Wed, 5 Oct 2005 08:36:09 -0300 (ADT) Received: obelix.askesis.nl 172.31.0.1 from 172.31.1.8 172.31.1.8 via HTTP with MS-WebStorage 6.0.6249 Received: from Panoramix by obelix.askesis.nl; 05 Oct 2005 13:36:11 +0200 Subject: Help with simple SQL query? From: Joost Kraaijeveld To: "Pgsql-sql@postgresql.org" Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Wed, 05 Oct 2005 13:35:32 +0200 Message-Id: <1128512132.3655.200.camel@Panoramix> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.332 required=5 tests=[AWL=-0.188, FORGED_RCVD_HELO=0.05, TO_ADDRESS_EQ_REAL=0.47] X-Spam-Level: X-Archive-Number: 200510/31 X-Sequence-Number: 22884 Hi, I have 2 tables with the following columns: order: order_id, order_price orderline: parent_order_id, orderline_price I want all orders order where _price <> sum(orderline_price). What is wrong with the following query: select order_id from order, orderline where order_id = parent_order_id and order_price <> (select sum(orderline_price) from orderline group by parent_order_id) It reports "ERROR: more than one row returned by a subquery used as an expression" which seems right (the select sum() returns multiple rows?), but I cannot get query right. Can someone help? TIA -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 e-mail: J.Kraaijeveld@Askesis.nl web: www.askesis.nl