Basically you would use COUNT to sum by UID. therefore
COUNT([uid]) will give a warning:
Warning: Null is excluded by aggregation or other SET operation.
when used with a left join where the counted object does not exist.
Using COUNT(*) in this case will also lead to incorrect results, since you would have to calculate the total number of results received (i.e. parents).
Using COUNT([uid]) is a valid way of counting, and a warning is nothing more than a warning. However, if you are interested, and you want to get the true number of uids in this case, you can use:
SUM(CASE WHEN [uid] IS NULL THEN 0 ELSE 1 END) AS [new_count]
This would not add a lot of overhead to your request. (checked by mssql 2008)
Mat Traherne Jan 08 '13 at 13:42
source share