title: UNION / GROUP BY - Prevent NULL values
body: <p>I have three MySQL tables containing weather observations. Now I'm trying to query data out of all these tables grouped by hour. The tables look like:</p>
  
  <pre><code>TABLE 1
  --------------------------------------------------------------------
  station     time        temperature     pressure        humidity
  --------------------------------------------------------------------
  10637       1520512345  22.9            NULL            NULL
  
  TABLE 2
  -------------------------------------------------------------------
  station     time        temperature     pressure        humidity
  -------------------------------------------------------------------
  10637       1520512345  NULL            1016            NULL
  
  TABLE 3
  -------------------------------------------------------------------
  station     time        temperature     pressure        humidity
  -------------------------------------------------------------------
  10637       1520512345  NULL            NULL            76
  </code></pre>
  
  <p>Currently, I use <code>UNION</code> along with <code>GROUP BY</code> to query an hourly aggregation:</p>
  
  <pre><code>SELECT *
  FROM ((SELECT `time`,`temperature`,`pressure`,`humidity`
         FROM `table_1`
         WHERE `station` = 10637
        ) UNION
        (SELECT `time`,`temperature`,`pressure`,`humidity`
         FROM `table_2`
         WHERE `station` = 10637
        ) UNION
        (SELECT `time`,`temperature`,`pressure`,`humidity`
         FROM `table_3`
         WHERE `station` = 10637
        )
       ) AS `hourly`
  GROUP BY DATE_FORMAT(FROM_UNIXTIME(`time`), '%Y %m %d %H')
  ORDER BY `time`
  </code></pre>
  
  <p>The query works. It takes one of the available rows for each hour. But as the example shows, some tables contain data that is not available in the others. That causes many unnecessary NULL values in the output. How do I need to change the query so the output contains an aggregation of all data that's <code>NOT NULL</code>?</p>