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 2FF939DCA0D for ; Mon, 13 Feb 2006 15:24:18 -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 95710-01 for ; Mon, 13 Feb 2006 15:24:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from nelson.osl.com (216-21-133-120.ip.van.radiant.net [216.21.133.120]) by postgresql.org (Postfix) with ESMTP id 903189DC83C for ; Mon, 13 Feb 2006 15:24:11 -0400 (AST) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Subject: Re: Problems with distinct Date: Mon, 13 Feb 2006 11:24:09 -0800 Message-ID: <144D12D7DD4EC04F99241498BB4EEDCC20D48B@nelson.osl.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] Problems with distinct Thread-Index: AcYw0nxQjzPsior1RJmH+jTottccCQAAFMaQ From: "Owen Jacobson" To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.108 required=5 tests=[AWL=0.108] X-Spam-Score: 0.108 X-Spam-Level: X-Archive-Number: 200602/140 X-Sequence-Number: 24150 Andreas Joseph Krogh wrote: > Any idea why this works: >=20 > SELECT distinct(g.groupname), g.id, g.p_id FROM onp_group g,=20 > onp_group g2 > WHERE g.id IN(SELECT g2.id UNION SELECT group_id FROM=20 > onp_group_children WHERE=20 > child_id =3D g2.id) > AND g2.id IN(1,2,109,105, 112); >=20 > And not this: >=20 > SELECT g.id, g.p_id, distinct(g.groupname) FROM onp_group g,=20 > onp_group g2 > WHERE g.id IN(SELECT g2.id UNION SELECT group_id FROM=20 > onp_group_children WHERE=20 > child_id =3D g2.id) > AND g2.id IN(1,2,109,105, 112); Distinct is an SQL keyword, not a function. The former is exactly = equivalent to SELECT DISTINCT g.groupname, g.id, .... FROM .... except that the first field is inside a (trivial) expression that makes = it look like a function call.