Figure out how to do group by max on id for two joins