Jump to content

get data from different table based on another table


Recommended Posts

I have 2 tables that I need to get data from.

 

table 1

id, city, city_perm_sup, city_temp_sup, city_perm_dem, city_temp_dem

1  test           1                  5                     15                      2

1  test2         5                   8                      9                      1

...

 

table 2

id,   supp

1      Autos

2      Timber

...

 

I need to select the supp field from table 2 where its id is equal to the fields in table 1 and echo them out.  I dont know how to do that though.  Do I need to add another table?  More than 1 query, I can think of doing it with 5 queries?

 

SELECT S.supp FROM " . $pre . "city C INNER JOIN " . $pre . "supp S ON ??? = S.id WHERE ???;

Errrr....  Read an article or two on database normalization and you'll wonder how you ever did without it.

 

 

So what exactly does table2.id map to in table1?  Please tell me that you don't have a different table2 for each city?

Table 1 has all the cities in it, with the table 2 id under the columns city_perm_sup, city_temp_sup, city_perm_dem, city_perm_sup

 

Table 2 has all the supp.

 

each city has 2 supplies and 2 demands, one supply and one demand changes, and the other doesnt.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.