title: MySQL count in same table including zero count values
body: <p>I have this table structure with data:</p>
  
  <pre><code>INSERT INTO `test` (`id`, `email`, `id_user_ref`, `name`) VALUES
  (1, 'email@gmail.com', NULL, 'Mike'),
  (2, 'email2@gmail.com', '1', 'Jhonny'),
  (3, 'email3@gmail.com', '1', 'Michael'),
  (4, 'email4@gmail.com', '2', 'Jorhe'),
  (5, 'email5@gmail.com', '3', 'Mia');
  </code></pre>
  
  <p>I need to count the id_user_ref for all users with this query:</p>
  
  <pre><code>SELECT id, COUNT(name) AS refNr FROM test GROUP BY id_user_ref
  HAVING id_user_ref IS NOT NULL;
  </code></pre>
  
  <p>This works but the problem is that i need to display all results even if the count result is 0.</p>
  
  <p>I tried several left joins with the same table but without any success.</p>
  
  <p>The output should be:</p>
  
  <pre><code>id  refNr
  1    2
  2    1
  3    1
  4    0
  5    0
  </code></pre>