Getting an order from query
Posted 27 April 2006 - 11:17 PM
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 name
And the second table has these:
I 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' ASC
To order by nation id
The 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.
Posted 28 April 2006 - 12:48 AM
"select * from table1 t1, table2 t2 order by t2.population asc"
or its more likely you'll want to join the two tables on their common key
"select * from table1 t1 INNER JOIN table2 t2 on t1.nationid = t2.nationid order by t2.population asc"
Posted 28 April 2006 - 02:00 AM
Edit: Works perfectly thanks a ton!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users