title: Select count for each distinct row (mysql and php)
body: <p>I am using mysql and php.</p>
  
  <p>I have a table with one column.  I can show unique rows by:</p>
  
  <pre><code>select distinct id from id_table
  </code></pre>
  
  <p>This might show</p>
  
  <pre><code>1
  2
  3
  5
  </code></pre>
  
  <p>What I want to do is show the number of 1's, 2's, etc there are.</p>
  
  <p>I could do</p>
  
  <pre><code>select count(id) from id_table where id = 1
  </code></pre>
  
  <p>But then I have to run a query for every... single... row... And with hundreds of thousands of rows, not good.</p>
  
  <p>Is there a way to return an array of the counts of each distinct item</p>
  
  <p>Data</p>
  
  <pre><code>1, 1, 1, 2, 3, 3, 5
  </code></pre>
  
  <p>Results</p>
  
  <pre><code>3, 1, 2, 1
  </code></pre>
  
  <p>Thanks</p>