title: How to count the number of grouped rows in mysql when I already count the total rows
body: <p>I have the below table and I want to do the following:</p>
  
  <ol>
  <li><p>Count the number of times each item appears in the table</p></li>
  <li><p>Count the <code>DISTINCT</code> number of items</p></li>
  <li><p>Group the items by name</p>
  
  <pre><code>+-------+---------+
  |  id   |  names  |
  +-------+---------+
  |   1   |  Apple  |
  |   2   |  Orange | 
  |   3   |  Grape  | 
  |   4   |  Apple  | 
  |   5   |  Apple  | 
  |   6   |  Orange | 
  |   7   |  Apple  | 
  |   8   |  Grape  |  
  +-------+---------+
  </code></pre>
  
  <p>For the 1. and 3. points I have the following query which works quite well:</p>
  
  <pre><code>SELECT * , 
     COUNT(names) as count_name, 
     FROM tbl_products WHERE type = '1' 
     GROUP BY names
  </code></pre>
  
  <p>So I get:</p>
  
  <pre><code>Apple  (4)
  Orange (2)
  Grape  (2)
  </code></pre></li>
  </ol>
  
  <p>Now I want to also count the number of grouped by rows and added a line to count the distinct elements, however there is some problem, since MySQL accepts the query but cannot output a result:</p>
  
  <pre><code>SELECT * , 
     COUNT(names) as count_name, 
     COUNT(DISTINCT names) as count_total 
     FROM tbl_products WHERE type = '1' 
     GROUP BY names
  </code></pre>
  
  <p>Can anyone advice what might be the problem?</p>
  
  <p>EDIT: For more clearance I want to get a table like this:</p>
  
  <pre><code>    +-------+---------+------------+-------------+
      |  id   |  names  |  count_ctg | count_total |
      +-------+---------+------------+-------------+
      |   1   |  Apple  |      4     |      3      |
      |   2   |  Orange |      2     |      3      |
      |   3   |  Grape  |      2     |      3      |
      +-------+---------+------------+-------------+
  </code></pre>