I am stuck with a query for some time since today morning. The query will show all records from table A and count of a column in table B, which includes 0 values if there are no occurrences (This is working fine) But the moment I am joining table C to extract the corresponding description of each record from table B, all the 0 value records are omitted!!
Here is my Query 1 (working fine w/o description field) (see screenshot of result result of Query1)
SELECT aa.awardcode, aa.year_grp, aa.awardqty, COUNT(aw.stud_code) as
stud_count from awardallocation AS aa
LEFT JOIN awardwinner as aw
ON aa.awardcode = aw.awardcode
AND aa.year_grp = aw.year_grp
AND aw.year = '$year'
AND aa.status = 1
AND aw.awardstatus = 1
GROUP BY aa.awardcode, aa.year_grp
Here is Query 2 (NOT displaying any record with Zero values when Description column is added)
SELECT aa.awardcode, ad.award_description, aa.year_grp, aa.awardqty,
COUNT(aw.stud_code) from awardallocation AS aa
LEFT JOIN awardwinner as aw
ON aa.awardcode = aw.awardcode
AND aa.year_grp = aw.year_grp
INNER JOIN award as ad
ON aa.awardcode = ad.awardcode
AND aw.year = 2017
AND aa.status = 1
AND aw.awardstatus = 1
GROUP BY aa.awardcode, aa.year_grp
What condition should I add to Query2 to force it to display Zero values?
NB: I am using MySQL. Column: awardcode is a present in all three tables and is unique in Award table. Column: year_grp is present in Awardallocation and Awardwinner table.
Thank you.