Jump to content

get data from different table based on another table


peranha

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 ???;

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.