X-Original-To: pgsql-php@postgresql.org Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) by postgresql.org (Postfix) with ESMTP id 5E83647638D for ; Fri, 7 Mar 2003 00:30:47 -0500 (EST) Received: (from root@localhost) by houston.familyhealth.com.au (8.11.6/8.11.6) id h275UqT90367 for pgsql-php@postgresql.org; Fri, 7 Mar 2003 13:30:52 +0800 (WST) (envelope-from chriskl@familyhealth.com.au) Received: from mariner (mariner.internal [192.168.0.101]) by houston.familyhealth.com.au (8.11.6/8.9.3) with SMTP id h275Un790277; Fri, 7 Mar 2003 13:30:49 +0800 (WST) Message-ID: <02c901c2e46a$b6841150$6500a8c0@fhp.internal> From: "Christopher Kings-Lynne" To: "ryanne cruz" , References: <1047013864.3e6829e837bdb@mail.up.edu.ph> Subject: Re: querying from 3 tables Date: Fri, 7 Mar 2003 13:30:49 +0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/) X-Archive-Number: 200303/4 X-Sequence-Number: 1916 > i am given the esourceid and i need to query the brgyid and the households of > a particular esourceid: query1="select brgyid, households from table1 where > esourceid=$esourceid;" > > the resulting brgyid will then be used to query for the munprovid in table2: > query2="select munprovid from table2 where brgyid=(query1);" > > the resulting munprovid will then be used to query for the geom column: > "select geom from table3 where munprovid=(query2);" > > my question is, how do i do this? any ideas? You can do this: select geom from table3 where munprovid=(select munprovid from table2 where brgyid=(select brgyid, households from table1 where esourceid=$esourceid)); Chris