Código PHP:
SELECT p.testdim, p.testdate, h.codi,hf.status, h.date0, datediff(now(), h.date0) AS diesinsemin, h.parts, h.curservices, a.herd_id, max( a.parity ) , max( a.endparitydate )
FROM production p, herd h, ag_parity a, herd_females hf
where p.herd_id = a.herd_id
AND a.herd_id = h.herd_id
AND p.herd_id = h.herd_id
AND p.herd_id = hf.herd_id
GROUP BY a.herd_id
gracias
:P