I have the folowing tables:
Table student:
id name
1 foo
2 bar
3 baz
Table mark
student_id mark date
1 9 2011-08-10
1 20 2011-08-09
1 5 2011-08-08
2 12 2011-08-09
2 8 2011-08-10
3 10 2011-08-10
I want each student with their last mark, ie
foo 9
bar 8
baz 10
How can i do that with mysql?
EDIT: The point of this example is how to add a sorting condiction on the joined table.
You would use a
GROUP BYand theMAXaggregate function to create a recordset containing all students with their latest date. This recordset can then be joined back to the original tables to retrieve the other columns needed.The GROUP BY Statement
MAX([DISTINCT] expr)
SQL Statement