title: Get table row count using multiple table join
body: <p>I have Three tables <code>company_m</code> , <code>client_m</code> , <code>companyuser_m</code></p>
  
  <p><strong>company_m</strong></p>
  
  <pre><code> CompanyID  CompName    
  ----------+-----------
       7        Comp3 
       8        Comp2 
       9        Comp1 
       10       Company 
       11       Company4
  </code></pre>
  
  <p><strong>client_m</strong></p>
  
  <pre><code>clid    AttachToCompanyID   clname
  -----+--------------------+------
    1           7             client1
    2           7             client2
    6           8             client3
  </code></pre>
  
  <p><strong>companyuser_m</strong> </p>
  
  <pre><code>uid CompanyID   uname
  ---+---------+-------
   1    7         user1
   2    10        user2
  </code></pre>
  
  <p><strong>My Goal</strong></p>
  
  <p>I need to get the count of all clients and users of the corresponding company</p>
  
  <p><strong>Expected Output</strong></p>
  
  <pre><code>CompanyID   CompName    clientcount usercount
  ---------+-----------+--------------+--------
     7        Comp3          2           1
     8        Comp2          1           0
     9        Comp1          0           0
    10        Company 3      0           1
    11        Company4       0           0
  </code></pre>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>select company_m.CompanyID,company_m.CompName,
  count(client_m.AttachToCompanyID) as clientcount ,
  count(companyuser_m.CompanyID) as usercount from company_m
  left join client_m on client_m.AttachToCompanyID=company_m.CompanyID
  left join companyuser_m on companyuser_m.CompanyID=company_m.CompanyID
  group by company_m.CompanyID 
  </code></pre>
  
  <p>But the above code not gives the correct output.</p>
  
  <p>check my <a href="https://dbfiddle.uk/?rdbms=mariadb_10.2&amp;fiddle=3080c1b3932c333654571199d9c77830" rel="nofollow noreferrer"><strong>fiddle</strong></a></p>