peranha Posted December 30, 2008 Share Posted December 30, 2008 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 ???; Quote Link to comment https://forums.phpfreaks.com/topic/138840-get-data-from-different-table-based-on-another-table/ Share on other sites More sharing options...
corbin Posted December 30, 2008 Share Posted December 30, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/138840-get-data-from-different-table-based-on-another-table/#findComment-725989 Share on other sites More sharing options...
peranha Posted December 30, 2008 Author Share Posted December 30, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138840-get-data-from-different-table-based-on-another-table/#findComment-725997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.