<p>In this query:</p>

<pre><code>SELECT COUNT(*) AS UserCount, Company.* FROM Company
LEFT JOIN User
ON User.CompanyId = Company.Id
WHERE Company.CanAccessSystem= true
AND(User.CanAccessSystem IS null OR User.CanAccessSystem = true)
GROUP BY Company.Id
</code></pre>

<p>I want to query a list of companies that can access a particular system as well as the number of users who can access the system inside the company.  </p>

<p>This query works for all cases except for one very important one.  If a company can access a the system but none of the users can, the Company disappears completely from the query (i.e.: Users.CanAccessSystem = false).  In that case, I just want the UserCount = 0.  </p>

<p>Example From Companies that Can Access the System:</p>

<pre><code>Users   Company Name
1       WidgetWorks
3       WidgetCompany
0       WidgesRUs
</code></pre>

<p>This system is on MySQL</p>

<p>Query Edit: Fixed a Typo "ON User.CompanyId = Company.Id"</p>

You should be counting the number of users for whom User.CanAccessSystem is true. Think of something like
```
```
count(case when User.CanAccessSystem then true end)
```
```
The case expression will return NULL in case User.CanAccessSystem is false (default), and
```
count(expr)
```
counts the number of items for which the expression is not null.
So... This?
```
```
SELECT COUNT(case when User.CanAccessSystem then true end) AS UserCount, Company.*
FROM Company LEFT JOIN User
ON Company.id = user.companyId   -- I had to guess, this seems to be missing in your query
WHERE Company.CanAccessSystem= true
GROUP BY Company.Id
```
```
p.s. I used LEFT JOIN instead of INNER JOIN in order not to exclude companies without users.