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 8689ED829A for ; Wed, 5 Oct 2005 08:47:17 -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 12626-01 for ; Wed, 5 Oct 2005 11:47:13 +0000 (GMT) Received: from loki.globexplorer.com (loki.globexplorer.com [208.35.14.101]) by svr1.postgresql.org (Postfix) with ESMTP id 8F247D7FE7 for ; Wed, 5 Oct 2005 08:47:14 -0300 (ADT) content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Subject: Re: Help with simple SQL query? X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Date: Wed, 5 Oct 2005 04:47:17 -0700 Message-ID: <71E37EF6B7DCC1499CEA0316A2568328024BBA0B@loki.wc.globexplorer.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] Help with simple SQL query? Thread-Index: AcXJoWadeE5ZSB/7TVai+9OipqcRmgAAMhGp From: "Gregory S. Williamson" To: "Joost Kraaijeveld" , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200510/32 X-Sequence-Number: 22885 Joost -- You are correct in stating that the problem is that the subquery returns = more than 1 row -- try using the NOT IN syntax ... it is not likely to = be very efficient but at least avoids the syntax error: select order_id from order, orderline where order_id =3D parent_order_id and order_price NOT IN (select sum(orderline_price) from orderline group = by parent_order_id) HTH, Greg Williamson DBA GlobeXplorer LLC -----Original Message----- From: pgsql-sql-owner@postgresql.org on behalf of Joost Kraaijeveld Sent: Wed 10/5/2005 4:35 AM To: Pgsql-sql@postgresql.org Cc:=09 Subject: [SQL] Help with simple SQL query? Hi, I have 2 tables with the following columns: order: order_id, order_price orderline: parent_order_id, orderline_price=20 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 =3D 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 --=20 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=20 ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster !DSPAM:4343bb5c106941059188129!