With this query, I get a result that is two short of the table because they are not included in count, and I would like get the NULL values in the result. To do this, I am pretty sure I need to use a subquery of some kind, but I am not sure how, since the attribute in question is an aggregate.
SELECT Equipment.SerialNo , Name, COUNT(Assignment.SerialNo)
FROM Equipment
INNER JOIN Assignment
ON Assignment.SerialNo = Equipment.SerialNo
GROUP BY Equipment.SerialNo, Name
You need to change your
inner jointo aleft outer joinand count something other thanAssignment.SerialNoif you want all rows counted — usecount(*)or another property that will not be null, ascount(column)does not include nulls for that column. If you don’t want nullAssignment.SerialNovalues included in the count, then continue aggregating on that column.An inner join by definition will skip values where
Assignment.SerialNoisNULL— an outer join will include them.