title: Count SQL results depending on two rows
body: <p>Here an example of my SQL structure:</p>
  
  <pre><code>magazines
       magazines.id
       magazines.templateId
       magazines.userId
  </code></pre>
  
  <p>I would like to count the number of times a user have used a specific template id.</p>
  
  <p>Considering 3 templates id : 100, 101 and 102 and considering 5 users (10, 20, 30, 40, 50). here is an example of the SQL datas:</p>
  
  <pre><code>magazines
       1, 100, 10
       2, 100, 20
       3, 100, 30
  </code></pre>
  
  <p>Here, 3 differents users have the template #100. But the result of the query should be [100 = 1] because it's different users. On the other hand, if I have :</p>
  
  <pre><code>magazines
       1, 100, 10
       2, 100, 10
  </code></pre>
  
  <p>I should have templateId [100 = 2].</p>
  
  <p>I tried multiple queries with GROUP BY and UNIQUE, by results are completely wrong. If someone can help, thanks.</p>