... ORDER BY h.codi GROUP BY a.herd_id LIMIT 0 , 30
... GROUP BY a.herd_id ORDER BY h.codi LIMIT 0 , 30