I am trying to get all records from my tables (groups, fiches, clients, goals, factures) by using left join to get results, and get 0 if the user id is not present (ex : no goal assigned to the membre) I dont know if i explain effectively but here is my query :
select CONCAT(s.firstname, ' ', s.lastname) AS Membre, g.achievement AS Objectif, count(l.assigned) AS `num_l`, count(c.id_fiche) AS `num_c`,
(count(c.id_fiche)/count(l.assigned))*100 AS `perc`, SUM(f.total) AS `glob`, (g.achievement - SUM(f.total)) AS `rest`, (SUM(f.total)/g.achievement)*100 AS `taux`
from `groups` s
LEFT JOIN `fiches` l ON s.id_membre=l.assigned LEFT JOIN `clients` c ON l.id=c.id_fiche
LEFT JOIN `goals` g ON s.id_membre=g.id_membre LEFT JOIN `factures` f ON s.id_membre=f.addedfrom
WHERE l.dateassigned BETWEEN '2020-08-01' AND '2020-08-31' AND f.status=2
GROUP BY s.id_membre
All I get in the result is members who for whom the goal is assigned , but what i need is all members, and for whom the goal is not assigned get 0 in fields related to goal. Thank you.