I have two tables inside my MySQL database and i add and retrieve information via PHP.
The first, contains entries like this:
id username
21 user123
22 user65
The second, contains entries like this:
level id value
1 21 188
2 21 333
3 21 567
1 22 78
The id in table 1 is the same id used in table 2. I'm trying to retrieve the 'value' for the highest 'level' in table 2. Currently, im able to get the highest level for any given id using:
query("SELECT MAX( level ) AS max FROM `table2` WHERE `id` LIKE '".$table1ID."'");
Where i'm stuck is how to then get the 'value' based on that particular 'level' and 'id', is a join needed?
EDIT: What i need is an SQL statement that would return '567' as that is the 'value' associated with the highest 'level' for the 'id' 21. Basically, for table 2, given an 'id' (21 for example), the sql statement would find the highest 'level' for that 'id', and return the 'value', which would be 567.