shawnwmorris
Programmer
I am new with FoxPro 9.0 (I know it is antiquated but it is what we have here at my new job)
I am attempting to create a query that will show all of the records from one table (Types) and the count of the occurrences on from another table. It sounds to me like a simple Left OUTER Join but the problem is that only the matching records from both tables are returned. I'd like to show all of the Types even if there isn't any instances of them in the occurrences table. My ideal results would be:
Type Count of occurances
Type 1 234
Type 2 59
Type 3 0 or NULL
Type 4 0 or NULL
Type 5 5
Type 6 89
My SQL is below:
SELECT PolicyIndType.poltype, COUNT(riskfile.poltype) FROM Policyindtype LEFT OUTER JOIN riskfile ON Policyindtype.Poltype = riskfile.poltype WHERE riskfile.cancelled >= DATE(YEAR(ldFirstofMonth)-1,01,01) AND riskfile.cancelled < DATE(YEAR(EndThisYear)-1,MONTH(EndThisYear),DAY(EndThisYear)) AND riskfile.company='002' GROUP BY PolicyIndType.Poltype
Where am I going wrong?
I am attempting to create a query that will show all of the records from one table (Types) and the count of the occurrences on from another table. It sounds to me like a simple Left OUTER Join but the problem is that only the matching records from both tables are returned. I'd like to show all of the Types even if there isn't any instances of them in the occurrences table. My ideal results would be:
Type Count of occurances
Type 1 234
Type 2 59
Type 3 0 or NULL
Type 4 0 or NULL
Type 5 5
Type 6 89
My SQL is below:
SELECT PolicyIndType.poltype, COUNT(riskfile.poltype) FROM Policyindtype LEFT OUTER JOIN riskfile ON Policyindtype.Poltype = riskfile.poltype WHERE riskfile.cancelled >= DATE(YEAR(ldFirstofMonth)-1,01,01) AND riskfile.cancelled < DATE(YEAR(EndThisYear)-1,MONTH(EndThisYear),DAY(EndThisYear)) AND riskfile.company='002' GROUP BY PolicyIndType.Poltype
Where am I going wrong?