SELECT c.timestamp, c.wert, UNIX_TIMESTAMP(c.timestamp) AS unix_time, a.wert FROM (SELECT c.timestamp AS stamp1, max(a.Zeitstempel) AS stamp2 FROM Counter.`99999910` as c LEFT JOIN alt.`statusanz` AS a ON c.timestamp >= a.Zeitstempel GROUP BY c.timestamp) LEFT JOIN c ON c.timestamp = stamp1 LEFT JOIN a ON a.Zeitstempel = stamp2;