Re: Problems with distinct

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problems with distinct
Date: 2006-02-13 19:22:00
Message-ID: 3717.1139858520@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Andreas Joseph Krogh <andreak(at)officenet(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Owen Jacobson 2006-02-13 19:24:09 Re: Problems with distinct
Previous Message Andreas Joseph Krogh 2006-02-13 19:19:30 Problems with distinct