title: MYSQL UNION GROUP BY
body: <p>I'm doing this select statement:</p>
  
  <pre><code>SELECT * FROM (
  SELECT COUNT(t.text) as count, COUNT(DISTINCT(t.from_user_id)) as usercount, DATE_FORMAT(t.created_at,'%Y-%m-%d %H:00') datepart 
  FROM TABLE1 t WHERE t.created_at &gt;= '2015-08-12 00:00:00' AND t.created_at &lt;= '2015-08-13 18:30:00' AND t.eliminar IS NULL 
  GROUP BY datepart) as t
  UNION ALL
  SELECT * FROM (
  SELECT COUNT(b.id) as count, COUNT(DISTINCT(b.from_user_id)) as usercount, DATE_FORMAT(b.created_at,'%Y-%m-%d %H:00') datepart 
  FROM TABLE2 b WHERE b.created_at &gt;= '2015-08-12 00:00:00' AND b.created_at &lt;= '2015-08-13 18:30:00' AND b.eliminar IS NULL 
  GROUP BY datepart) as x GROUP BY datepart 
  </code></pre>
  
  <p>this select gets this:</p>
  
  <p><a href="https://i.stack.imgur.com/gGavX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gGavX.png" alt="enter image description here"></a></p>
  
  <p>I'm trying to view with <code>datepart</code> grouped but I can't, any idea what I'm doing wrong?</p>
  
  <p>TABLE2 only have (id,from_user_id,eliminar) and all are NULL except <code>created_at</code>, in this row I have entire 2015 year by day and hour, same format as TABLE1</p>