X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id B13889DCB57 for ; Mon, 13 Feb 2006 15:19:37 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92598-05 for ; Mon, 13 Feb 2006 15:19:37 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 42EF29DCA22 for ; Mon, 13 Feb 2006 15:19:35 -0400 (AST) Received: from ns1.officenet.no (ns1.officenet.no [193.212.174.3]) by svr4.postgresql.org (Postfix) with ESMTP id 626A35AF835 for ; Mon, 13 Feb 2006 19:19:36 +0000 (GMT) Received: from [193.212.174.32] by ns1.officenet.no with esmtps (TLSv1:AES256-SHA:256) (Exim 4.60) (envelope-from ) id 1F8jEP-00064R-Rj for pgsql-sql@postgresql.org; Mon, 13 Feb 2006 20:19:32 +0100 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-sql@postgresql.org Subject: Problems with distinct Date: Mon, 13 Feb 2006 20:19:30 +0100 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200602132019.30393.andreak@officenet.no> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/138 X-Sequence-Number: 24148 Any idea why this works: SELECT distinct(g.groupname), g.id, g.p_id FROM onp_group g, onp_group g2 WHERE g.id IN(SELECT g2.id UNION SELECT group_id FROM onp_group_children WH= ERE=20 child_id =3D g2.id) AND g2.id IN(1,2,109,105, 112); And not this: SELECT g.id, g.p_id, distinct(g.groupname) FROM onp_group g, onp_group g2 WHERE g.id IN(SELECT g2.id UNION SELECT group_id FROM onp_group_children WH= ERE=20 child_id =3D g2.id) AND g2.id IN(1,2,109,105, 112); The *only* difference is that the distinct-clause changed place... =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager gpg public_key: http://dev.officenet.no/~andreak/public_key.asc =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Hoffsveien 17 | know how to do a thing and to watch | PO. Box 425 Sk=F8yen | somebody else doing it wrong, without | 0213 Oslo | comment. | NORWAY | | Phone : +47 22 13 01 00 | | Direct: +47 22 13 10 03 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+