Re: Must I use DISTINCT?

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Must I use DISTINCT?
Дата
Msg-id 20090205220522.G36179@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Must I use DISTINCT?  (Michael B Allen <ioplex@gmail.com>)
Список pgsql-sql
On Thu, 5 Feb 2009, Michael B Allen wrote:

> 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.

Would something like:SELECT e.eid, e.name FROM entry e WHERE e.eid = 120 AND(e.ownid = 66 OR e.aid in (select a.aid
fromaccess a))
 
do what you wnat?


В списке pgsql-sql по дате отправления:

Предыдущее
От: Michael B Allen
Дата:
Сообщение: Re: Must I use DISTINCT?
Следующее
От: Raj Mathur
Дата:
Сообщение: Re: Must I use DISTINCT?