SELECT DISTINCT ku.*, lu.* FROM (SELECT GROUP_CONCAT(id) AS id_list, status, datetime, day_name, hour_am_pm, COUNT(*) AS row_count FROM (SELECT *, DAYNAME(datetime) AS day_name, CONCAT(IF(HOUR(datetime) > 12, HOUR(datetime) - 12, HOUR(datetime)), ' ', IF(HOUR(datetime) >= 12, 'PM', 'AM')) AS hour_am_pm FROM tbl_heatmap WHERE WEEK(datetime) = WEEK(CURDATE()) AND DAYOFWEEK(datetime) = 2 ) AS subquery GROUP BY hour_am_pm) lu JOIN (SELECT GROUP_CONCAT(id) AS id_list, status, datetime, day_name, hour_am_pm, COUNT(*) AS row_count FROM (SELECT *, DAYNAME(datetime) AS day_name, CONCAT(IF(HOUR(datetime) > 12, HOUR(datetime) - 12, HOUR(datetime)), ' ', IF(HOUR(datetime) >= 12, 'PM', 'AM')) AS hour_am_pm FROM tbl_heatmap WHERE WEEK(datetime) = WEEK(CURDATE()) AND DAYOFWEEK(datetime) = 3 ) AS subquery GROUP BY hour_am_pm) ku;