Im trying to get results from 2 tables. The first table there is the Ids with info, from the 2nd table I want to count existing for each id from the 1st table based on some condition. here is my code:
SELECT p.stId, count(att.adate)
FROM payments p
LEFT JOIN Attendence att ON att.stId = p.stId
where p.cyear = 2018 and p.cmonth = 3 and p.cId = 10
and att.adate between '2018/03/01' and '2018/03/30 23:59:59.999' and att.cid
= 10
GROUP BY p.stId
from the first table(p) I have 3 ids. but when I run this it returns only 1 id. the ids that not exists in the 2nd table (t) it does NOT give any results. what I want to do is that if there is no id in the 2nd table, I want to return a 0 for the count (count(att.adate))
Thanks.