Re: Locating all Children given Set of Parents

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Locating all Children given Set of Parents
Дата
Msg-id 200305130947.46844.josh@agliodbs.com
обсуждение исходный текст
Ответ на Locating all Children given Set of Parents  (Adam Sherman <adam@tritus.ca>)
Ответы Re: Locating all Children given Set of Parents
Re: Locating all Children given Set of Parents
Список pgsql-sql
Adam,

> I have three tables: parents, children & parent_child_mm.
>
> (So Parents and Children are in a Many-to-Many relationship.)
>
> Given a set of Parents, say 1, 2 & 3, how do I retrieve all children in an
> efficient manner? (I want each child to appear only once.)

Easy:

Select children.*
from children where exists (select pc_id from parent_childwhere pc.child_id = children.idand pc.parent_id IN
($parent_id_list));

--
Josh Berkus
Aglio Database Solutions
San Francisco



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

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: N all-way relationship
Следующее
От: Adam Sherman
Дата:
Сообщение: Re: Locating all Children given Set of Parents