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 D42BD9DC848 for ; Mon, 13 Feb 2006 15:22:08 -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 93610-05 for ; Mon, 13 Feb 2006 15:22:08 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id DE7CE9DCC1C for ; Mon, 13 Feb 2006 15:22:05 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id k1DJM0kB003718; Mon, 13 Feb 2006 14:22:00 -0500 (EST) To: Andreas Joseph Krogh cc: pgsql-sql@postgresql.org Subject: Re: Problems with distinct In-reply-to: <200602132019.30393.andreak@officenet.no> References: <200602132019.30393.andreak@officenet.no> Comments: In-reply-to Andreas Joseph Krogh message dated "Mon, 13 Feb 2006 20:19:30 +0100" Date: Mon, 13 Feb 2006 14:22:00 -0500 Message-ID: <3717.1139858520@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.109 required=5 tests=[AWL=0.109] X-Spam-Score: 0.109 X-Spam-Level: X-Archive-Number: 200602/139 X-Sequence-Number: 24149 Andreas Joseph Krogh writes: > 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 WHERE > child_id = 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 WHERE > child_id = g2.id) > AND g2.id IN(1,2,109,105, 112); DISTINCT is not a function, it's a modifier attached to SELECT. The parentheses in your first example are a no-op. regards, tom lane