Re: querying from 3 tables

Re: querying from 3 tables

am 07.03.2003 06:11:04 von ryanne cruz

=20
hi list.=20
=20
i have 3 tables with the following columns:=20
=20
table1: esourceid (primary key), brgyid, households=20
table2: brgyid (primary key), munprovid=20
table3: munprovid (primary key), geom=20
=20
i am given the esourceid and i need to query the brgyid and the household=
s of=20
a particular esourceid: query1=3D"select brgyid, households from table1 w=
here=20
esourceid=3D$esourceid;"=20
=20
the resulting brgyid will then be used to query for the munprovid in tabl=
e2:=20
query2=3D"select munprovid from table2 where brgyid=3D(query1);"=20
=20
the resulting munprovid will then be used to query for the geom column:=20
"select geom from table3 where munprovid=3D(query2);"=20
=20
my question is, how do i do this? any ideas? =20

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Re: querying from 3 tables

am 07.03.2003 06:30:49 von Christopher Kings-Lynne

> 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


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: querying from 3 tables

am 07.03.2003 07:20:01 von Francesco Piccinini

What about the following:

select a.brgyd,a.households,b.munprovid,c.geom
from table1 a, table2 b, table3 c
where a.esourceid=$esourceid and
a.brgyd=b.brgyd and
b.munprovid=c.geom ;


Bye, Francesco

ryanne.cruz@up.edu.ph wrote:

>
> hi list.
>
> i have 3 tables with the following columns:
>
> table1: esourceid (primary key), brgyid, households
> table2: brgyid (primary key), munprovid
> table3: munprovid (primary key), geom
>
> 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?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Re: querying from 3 tables

am 07.03.2003 07:22:44 von Francesco Piccinini

What about the following:

select a.brgyd,a.households,b.munprovid,c.geom
from table1 a, table2 b, table3 c
where a.esourceid=$esourceid and
a.brgyd=b.brgyd and
b.munprovid=c.geom ;


Bye, Francesco

ryanne.cruz@up.edu.ph wrote:

>
> hi list.
>
> i have 3 tables with the following columns:
>
> table1: esourceid (primary key), brgyid, households
> table2: brgyid (primary key), munprovid
> table3: munprovid (primary key), geom
>
> 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?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: querying from 3 tables

am 07.03.2003 07:25:56 von Francesco Piccinini

Sorry ...... this is the rigth query

What about the following:

select a.brgyd,a.households,b.munprovid,c.geom
from table1 a, table2 b, table3 c
where a.esourceid=$esourceid and
a.brgyd=b.brgyd and
b.munprovid=c.munprovid ;


Bye, Francesco

ryanne.cruz@up.edu.ph wrote:

>
> hi list.
>
> i have 3 tables with the following columns:
>
> table1: esourceid (primary key), brgyid, households
> table2: brgyid (primary key), munprovid
> table3: munprovid (primary key), geom
>
> 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?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org