select b.reference, b.description, date_format (b.date, "%d/%m/%Y"), b.prix, comptes.nom
from tarifs b,comptes, (
  select reference, date, max(date) as ladate 
  from tarifs
  where date < '2012-12-31'
  group by reference
  ) a
where b.date = a.ladate
and b.compte = comptes.id
and b.reference = a.reference
order by b.reference