Re: A simple join question that may stump you

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: A simple join question that may stump you
Дата
Msg-id web-126749@davinci.ethosmedia.com
обсуждение исходный текст
Ответ на A simple join question that may stump you  (nospam4@pobox.com (Ross Smith))
Список pgsql-sql
Ross,

>    ID  FLAG
> ----- -----
>     1     1
>     2     1
>     2     2
>     3     1
>     3     2
>     3     3
>
> and table B:
>
>  FLAG
> -----
>     1
>     2
>
> I want to find all id's from table A that have every flag in table B
> but no extra flags.  So, I'd end up with:
>
>    ID
> -----
>     2

Try looking at the INTERSECT and EXCEPT join types.  Thus, in pseudo-sql
you'd need:

SELECT A.ID
WHERE Count A JOIN B = Count B
AND Count A EXCEPT B = 0

Assuming that all rows in A are unique.

-Josh


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Вложения

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

Предыдущее
От: Frederick Klauschen
Дата:
Сообщение: PARSER ERROR persists ....
Следующее
От: 71062.1056@compuserve.com (--CELKO--)
Дата:
Сообщение: Re: Simple Query HELP!!!