distinct not working in a multiple join

From: David Rio Deiros <driodeiros(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: distinct not working in a multiple join
Date: 2006-02-09 23:33:09
Message-ID: 20060209233309.GA473@milhouse.digitaria.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-02-10 00:12:45 Re: Insert more than one t-uple in a single sql
Previous Message Rick Gigger 2006-02-09 23:29:26 Re: Insert more than one t-uple in a single sql