title: MySQL - query - Mix between DISTINCT and GROUP BY
body: <p>I have the following table:</p>
  
  <pre><code>SELECT * FROM tblTemp;
  +-----+---------------------+
  | id  | timestamp           |
  +-----+---------------------+
  |  84 | 2013-07-18 22:36:32 |
  |  85 | 2013-07-18 22:36:33 |
  |  88 | 2013-07-18 22:36:33 |
  |  89 | 2013-07-18 22:36:34 |
  | 263 | 2013-08-04 16:01:05 |
  | 264 | 2013-08-04 16:01:11 |
  | 272 | 2013-08-04 16:01:42 |
  | 273 | 2013-08-04 16:01:42 |
  | 274 | 2013-08-04 16:01:42 |
  | 275 | 2013-08-04 16:21:25 |
  | 276 | 2013-08-04 16:21:25 |
  | 279 | 2013-08-04 16:21:26 |
  | 280 | 2013-08-04 16:21:27 |
  | 281 | 2013-08-04 16:21:27 |
  +-----+---------------------+
  14 rows in set (0.00 sec)
  </code></pre>
  
  <p>First i want to remove all double timestamps in the view like this</p>
  
  <pre><code>SELECT DISTINCT timestamp FROM tblTemp;
  +---------------------+
  | timestamp           |
  +---------------------+
  | 2013-07-18 22:36:32 |
  | 2013-07-18 22:36:33 |
  | 2013-07-18 22:36:34 |
  | 2013-08-04 16:01:05 |
  | 2013-08-04 16:01:11 |
  | 2013-08-04 16:01:42 |
  | 2013-08-04 16:21:25 |
  | 2013-08-04 16:21:26 |
  | 2013-08-04 16:21:27 |
  +---------------------+
  9 rows in set (0.00 sec)
  </code></pre>
  
  <p>But this is not enough. I need the count, how many entries are in the DB each hour (without doubles) - about this: </p>
  
  <pre><code>+---------------------+-------+
  | timestamp           | count |
  +---------------------+-------+
  | 2013-07-18 22:00:00 | 3     |
  | 2013-08-04 16:00:00 | 6     |
  +---------------------+-------|
  </code></pre>
  
  <p>First i thought i can use the following command:</p>
  
  <pre><code>SELECT timestamp, COUNT(id) FROM tblTemp GROUP BY YEAR(timestamp), MONTH(timestamp), DAY(timestamp), HOUR(timestamp)
  </code></pre>
  
  <p>But it doesn't work fine. The command counts all rows :/</p>
  
  <pre><code>+---------------------+-------+
  | timestamp           | count |
  +---------------------+-------+
  | 2013-07-18 22:36:32 |     4 |
  | 2013-08-04 16:01:05 |    10 |
  +---------------------+-------+
  </code></pre>
  
  <p>It is not important, if the value in column timestamp is 2013-07-18 22:00:00 or 2013-07-18 22:36:32 or anything else as long as the time and date is identifiable.</p>
  
  <p>Thanks :)</p>