Re: Problems with distinct - Mailing list pgsql-sql

From Tom Lane
Subject Re: Problems with distinct
Date
Msg-id 3717.1139858520@sss.pgh.pa.us
Whole thread Raw
In response to Problems with distinct  (Andreas Joseph Krogh <andreak@officenet.no>)
Responses Re: Problems with distinct  (Andreas Joseph Krogh <andreak@officenet.no>)
List pgsql-sql
Andreas Joseph Krogh <andreak@officenet.no> 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


pgsql-sql by date:

Previous
From: Andreas Joseph Krogh
Date:
Subject: Problems with distinct
Next
From: "Owen Jacobson"
Date:
Subject: Re: Problems with distinct