SneakyMax Posted April 27, 2006 Share Posted April 27, 2006 Okay, this is my first post so don't go too hard on me...I've been using php for about 2 months now, got the basics. My problem is that for the thing that I am making online, it uses two different mysql tables to 'simplify' things, so I don't have too many columns.The first table, for my nation simulation, has these things:nation id, first name, last nameAnd the second table has these:nation idpopulationI have a script that lists all of the nations, and in order of different things. Such as nation id and nation name, using "SELECT * from [table1] ORDER BY 'nationid' ASCTo order by nation idThe problem is I don't know how to order it by population, since it's in a different table. The nation ids in table 2 go with the nation ids from table 1, but I don't know how to get the order of population from table 2, then use that order in table 1 to get the name.Hope it's not too confusing...it might have to do with sql, or mysql_fetch_array probably. Quote Link to comment https://forums.phpfreaks.com/topic/8588-getting-an-order-from-query/ Share on other sites More sharing options...
KrisNz Posted April 28, 2006 Share Posted April 28, 2006 you can either pull all the information from the second table out along with the first one.[code]"select * from table1 t1, table2 t2 order by t2.population asc"[/code]or its more likely you'll want to join the two tables on their common key[code]"select * from table1 t1 INNER JOIN table2 t2 on t1.nationid = t2.nationid order by t2.population asc"[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8588-getting-an-order-from-query/#findComment-31505 Share on other sites More sharing options...
SneakyMax Posted April 28, 2006 Author Share Posted April 28, 2006 No idea there was an INNER JOIN, looks like what I'm looking for thanks a ton.Edit: Works [i]perfectly[/i] thanks a ton! Quote Link to comment https://forums.phpfreaks.com/topic/8588-getting-an-order-from-query/#findComment-31526 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.