I want to select a row which has the highest ID and matches the id from another table, so I figured MAX was the way to go here. My query is like this: $prog_template_query = 'SELECT MAX(id), prog_id, acad_year, pdf, pdf_euro FROM prog_templates WHERE prog_id='.$prog_row["id"].' GROUP BY prog_id;';
The row I would expect it to return is the one which has the highest ID: Array (  => 192 [MAX(id)] => 192  => 6 [prog_id] => 6  => 2009 [acad_year] => 2009  => 1 [pdf] => 1  => 1 [pdf_euro] => 1 )
but instead it seems to be picking out the highest ID, but the year from another (older) row altogether, so it is a mixture of the two! Array (  => 192 [MAX(id)] => 192  => 6 [prog_id] => 6  => 2006 [acad_year] => 2006  => 1 [pdf] => 1  => 1 [pdf_euro] => 1 )
Can anyone help me here? Am I totally misunderstanding the way MAX works?
I'm afraid I have no idea what the GROUP BY bit is for either, but I can see that changing it to another field changes the results again!