title: SQL query for getting count and distinct
body: <p>I have the following table called <code>user_pin_tags</code> with the following data that I need to query and show distinct tags and a count of each:</p>
  
  <pre><code>| user_id | pin_id | tag_id |
  +---------+--------+--------+
      1     |   34   |   7
      2     |   34   |   7
      3     |   34   |   15   
      4     |   34   |   16   
      5     |   34   |   16   
      6     |   34   |   16   
  </code></pre>
  
  <p>Right now I am using the following query to get the distinct tag_ids</p>
  
  <pre><code>SELECT DISTINCT tag_id
  FROM user_pin_tags
  WHERE pin_id =  34
  </code></pre>
  
  <p>which gives the result of:</p>
  
  <pre><code>| tag_id |
  +--------+
      7
      15
      16
  </code></pre>
  
  <p>I need to modify this query to give the distinct tag_ids as well as the count within that pin_id, so I want to generate this result set:</p>
  
  <pre><code>| tag_id | count |
  +--------+-------+
      7    |   2
      15   |   1
      16   |   3
  </code></pre>
  
  <p>How can I modify this query to achieve this?</p>