Joining/querying unrelated tables - PLEASE HELP!
Posted: Sat Feb 27, 2010 6:06 pm
Please please please can someone help with this. I'm fairly new to php and mysql and am having some trouble returieving the data i want in the way that i want to.
i have set up three table. They are not exactly like this but this best explains the principles of my aim. These are their table structures.
1. States
-----
id
state
2. towns
-----
id
state_id
town
3. residents
--------
id
town_id
first_name
surname
etc etc........
I want have created a search form but am struggling with the sql. I want to perform a query whereby i can retrieve all the residents of one particular state, at the moment i only know how to do for the town.
I know i could do this by adding a state_id column to the residents table but i figured there must be a better way to do this i just cant figure it out. Can someone please help. Thanks.
Duncan
i have set up three table. They are not exactly like this but this best explains the principles of my aim. These are their table structures.
1. States
-----
id
state
2. towns
-----
id
state_id
town
3. residents
--------
id
town_id
first_name
surname
etc etc........
I want have created a search form but am struggling with the sql. I want to perform a query whereby i can retrieve all the residents of one particular state, at the moment i only know how to do for the town.
I know i could do this by adding a state_id column to the residents table but i figured there must be a better way to do this i just cant figure it out. Can someone please help. Thanks.
Duncan