From: | "Owen Jacobson" <ojacobson(at)osl(dot)com> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Problems with distinct |
Date: | 2006-02-13 19:24:09 |
Message-ID: | 144D12D7DD4EC04F99241498BB4EEDCC20D48B@nelson.osl.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Andreas Joseph Krogh wrote:
> 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 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Joseph Krogh | 2006-02-13 19:29:21 | Re: Problems with distinct |
Previous Message | Tom Lane | 2006-02-13 19:22:00 | Re: Problems with distinct |