join
をお探しですか およびgroup by
?
select f.id,
count(*) as num_rows,
sum(tare) as sum_tare
from history h join
temp_fetch f
on h.nom like concat('%', f.client, '%') or
h.commune like concat('%', f.commune, '%') or
h.type like concat('%', f.type, '%') or
h.mat like concat('%', f.matricule, '%') or
h.tare like concat('%', f.tare, '%')
where f.cancled = 0
group by f.id;