distinct not working in a multiple join - Mailing list pgsql-general

From David Rio Deiros
Subject distinct not working in a multiple join
Date
Msg-id 20060209233309.GA473@milhouse.digitaria.com
Whole thread Raw
Responses Re: distinct not working in a multiple join
List pgsql-general
Hi there,

I have some issues with the query attached at the end of this email.
If I run that query I got this output ( I have removed some of the
fields) despite the distinct clause:

QC Q&A  | www.xxx.com | 44281
QC Q&A  | www.xxx.com | 44281
WhyMAX? |             | 44285

But, and here is the weird thing, if I remove g.group_id from the
selection list then I got what I expected:

QC Q&A  | www.xxx.com | 44281
WhyMAX? |             | 44285
toto    | rufus       | 44286

Can someone explain me what is going on here? What am I missing?

Thanks for you help in advance,

David


            SELECT
                distinct ar.title,
                ar.raw_data,
                ar.upload_dt,
                ar.artifact_id,
                g.group_id,
                acl.read
            FROM
                artifact_acl acl,
                artifacts a,
                artifact_revisions ar,
                revisions_to_types rt,
                artifact_types at,
                groups g
            WHERE
                a.expire_dt > NOW() and
                acl.artifact_id = a.artifact_id and
                a.published_revision = ar.revision_id and
                ar.revision_id = rt.revision_id and
                rt.type_id = at.type_id and
                acl.group_id = g.group_id and
                a.suppress = false and
                at.is_resource = true and
                (
                acl.group_id = (
                                select
                                    group_id
                                from
                                    groups
                                where
                                    group_nm = 'ting'
                               )
                               OR
                acl.group_id = (
                                select
                                    group_id
                                from
                                    groups
                                where
                                    group_nm = 'tors'
                               )
                ) and
                acl.group_id IN (4,17,54,2,1,123) and
                acl.read = true and
                ((g.back_or_front = 'front') or
                 (g.group_nm = 'PR Admin'))
            GROUP BY
               ar.title
            ORDER BY
               ar.upload_dt DESC
            LIMIT 3;

pgsql-general by date:

Previous
From: Rick Gigger
Date:
Subject: Re: Insert more than one t-uple in a single sql
Next
From: Tom Lane
Date:
Subject: Re: Insert more than one t-uple in a single sql