Krono
Krono

Reputation: 1362

SQL - No Nulls on Left Join

I have been working with a Chart control in a WinForms Application, and have had some trouble with plotting the correct points - i have tried a multitude of things including the DataManipulator.InsertEmptyPoints, to no avail.

So, i decided to improve my SQL Query - which has been done, but it is still not including 0/Null Values - but i'm having some trouble with my left join - it's not returning any Null Values.

Query:

SELECT FC_Name , count (Findings.Findings_ID) AS 'NumFindings'
FROM FindingCategories
     LEFT JOIN Findingsubcategories ON Findingsubcategories.FC_ID = FindingCategories.FC_ID
     LEFT JOIN Findings ON Findings.FSC_ID = Findingsubcategories.FSC_ID
     -- LEFT JOIN Audit ON Audit.Audit_ID = Findings.AU_ID
     -- WHERE Audit.Audit_ID = 932
     GROUP BY FC_Name

The output of the query

Query with no Comment

Now, when i remove my comments and include the two lines in the query

enter image description here

Where as i want it to be something like:

FC_Name    | NumFindings
Category         1
Category         6
Category         1
Category         0/Null
Category         0/Null
Category         0/Null
Category         0/Null

What am i doing wrong?

Upvotes: 2

Views: 91

Answers (1)

Krono
Krono

Reputation: 1362

I managed to deduce that one of my joins was redundant and didnt do anything, the solution:

SELECT FC_Name, COUNT(Findings.Findings_ID) AS 'NumFindings'
FROM FindingCategories
 LEFT OUTER JOIN Findingsubcategories ON Findingsubcategories.FC_ID = FindingCategories.FC_ID
 LEFT OUTER JOIN Findings ON Findings.FSC_ID = Findingsubcategories.FSC_ID AND Findings.AU_ID = 932
 GROUP BY FC_Name

Upvotes: 3

Related Questions