X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4C29847636B for ; Tue, 13 May 2003 12:47:55 -0400 (EDT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id 8138B474E42 for ; Tue, 13 May 2003 12:47:54 -0400 (EDT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3030712; Tue, 13 May 2003 09:48:01 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Adam Sherman , pgsql-sql@postgresql.org Subject: Re: Locating all Children given Set of Parents Date: Tue, 13 May 2003 09:47:46 -0700 User-Agent: KMail/1.4.3 References: <184690000.1052842782@saturn> In-Reply-To: <184690000.1052842782@saturn> MIME-Version: 1.0 Message-Id: <200305130947.46844.josh@agliodbs.com> Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-31.6 required=5.0 tests=BAYES_10,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/232 X-Sequence-Number: 13397 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=20 from parent_child where pc.child_id =3D children.id and pc.parent_id IN ($parent_id_list) ); --=20 Josh Berkus Aglio Database Solutions San Francisco