title: How to COUNT DISTINCT record SQL?
body: <p>I have a script to count distinct id for registration once per year</p>
  
  <pre><code>SELECT COUNT(DISTINCT id),
  MONTH(reg_date), YEAR(reg_date)
  FROM reg_tbl
  WHERE YEAR(reg_date) IN (2013, 2014, 2015)
  </code></pre>
  
  <p>I want to have the data count each <code>id</code> only once per year even if it is returned more than once. I would also like the id to be counted in the maximum month it was registered. That is, if the <code>id</code> is registered in January, February and March of a specific year I would like it to be counted once but within the month of the latest registration.</p>