 SELECT *  FROM tableA AS a  LEFT JOIN tableB AS b     ON a.timestamp = b.timestamp     AND b.unitCode = 'CODE'      AND b.timestamp BETWEEN 'STARTDATETIME' AND 'ENDDATETIME' ORDER BY b.timestamp DESC`  