From: | Michael B Allen <ioplex(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Must I use DISTINCT? |
Date: | 2009-02-05 21:57:36 |
Message-ID: | 78c6bd860902051357j6edbb375jc1c52393ea8410d6@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Please consider the following SQL
SELECT e.eid, e.name
FROM entry e, access a
WHERE e.eid = 120
AND (e.ownid = 66 OR e.aid = a.aid)
The intent is to match one entry with the eid of 120. However I would
like to impose an additional constraint that either e.ownid must be 66
or e.aid must match the aid of an entry in the access table (there's
actually a lot more to the query but I think this should be sufficient
to illustrate my problem).
The problem is that the e.ownid is 66 and therefore the same entry is
returned for each access entry.
Of course I can simply SELECT DISTINCT but that seems like an improper
usage of DISTINCT here.
Is there an alternative way to write this query? I only want to select
from the access table for the purpose of constraining by aid.
Mike
--
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Jamie Tufnell | 2009-02-05 23:21:38 | Re: current_date vs 'now' |
Previous Message | Tom Lane | 2009-02-05 15:34:06 | Re: current_date vs 'now' |