Where clauses belong after the joins.
Since we're using outer joins we have to make sure the where clause criteria for the matching records is moved to the join or the outer join is negated.
in mySQL to simulate a full outer join we simple do a left and right join with a union ALL (union does a distinct which removes the duplicates)
SELECT tbldecedent.Name, tbldecedent.EngDate, Count(*) as Cnt
FROM yahrzeit
LEFT JOIN tbldecedent
ON CONCAT( yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName ) = tbldecedent.Name
AND DATE_FORMAT( CONCAT( yahrzeit.gregorianYear, '-', yahrzeit.gregorianMonthNum, '-', yahrzeit.gregorianDay ) , '%Y-%m-%d' ) = tbldecedent.EngDate
WHERE yahrzeit.confirmed = 1
AND tblDecedent.name is null -- add this to only show no matches.
GROUP BY tbldecedent.Name, tbldecedent.EngDate
UNION ALL
SELECT tbldecedent.Name, tbldecedent.EngDate, Count(*) as cnt
FROM yahrzeit
RIGHT JOIN tbldecedent
ON CONCAT( yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName ) = tbldecedent.Name
AND DATE_FORMAT( CONCAT( yahrzeit.gregorianYear, '-', yahrzeit.gregorianMonthNum, '-', yahrzeit.gregorianDay ) , '%Y-%m-%d' ) = tbldecedent.EngDate
AND yhrzeit.confirmed = 1
WHERE CONCAT( yahrzeit.firstName, ' ', yahrzeit.middleName, ' ', yahrzeit.lastName ) is null -- add this to only show no matches.
GROUP BY tbldecedent.Name, tbldecedent.EngDate
To better understand joins I recommend: https://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ the venn diagram approach is a good one.
Lastly, I don't recommend a select *, count()
with a group by containing only two fields. Select should only include the values in the group by plus
aggregates or constants. Current version of MySQL wouldn't let you get away with this without changing a global setting, and other engines simply don't support this method. MySQL extends the group by to allow it; but the results can be unexpected for the columns not listed in the group by . More on that in the docs: https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html