title: MySQL: Group By & Count Multiple Fields
body: <p>If I have a single field, say, project_id where I want to count the occurrences, I would do something like:</p>
  
  <pre><code>select project_id, count(project_id) as count from tbl group by project_id, order by count desc
  </code></pre>
  
  <p>What if I want to count the occurrences of a combination of two fields in the same table, i.e. count the number of rows where the combination of project_id and service_id are unique?</p>
  
  <p>So, so I have records in my table like:</p>
  
  <pre><code>project_id   service_id
  1            1
  1            2
  1            2
  1            2
  1            2
  1            3
  1            4
  1            4
  1            4
  
  
  I would want the result of my query to be something like:
  
  project_id   service_id   count
  1            1            1
  1            2            4
  1            3            1
  1            4            3
  </code></pre>