SELECT DISTINCT
CAST(`t1`.`ImportedOn` AS DATE) AS `DispatchDate`,
`t1`.`Order` AS `order`,
`t1`.`Operation` AS `QbOP`,
`t1`.`UserOpStatus` AS `OpsAway`,
`t1`.`UnloadingPoint` AS `Location`,
`t1`.`WorkCenter` AS `QbWC`,
`t1`.`LatestStartDate` AS `QbStartDay`,
`t1`.`LatestStartTime` AS `QbStartTime`,
`t2`.`Operation` AS `RcOP`,
`t2`.`WorkCenter` AS `RcWC`,
`t2`.`LatestStartDate` AS `lateststartdate`,
`t2`.`LatestStartTime` AS `lateststarttime`,
`wc`.`CellName` AS `CellName`,
IF((`wooc`.`ConfirmationDate` IS NULL),
'Open',
IF((`t1`.`UserOpStatus` = 'run'),
'Running',
'Done')) AS `Status`
FROM
(((`workorderoperationschedule` `t1`
LEFT JOIN `workorderoperationschedule` `t2` ON (((`t1`.`Order` = `t2`.`Order`)
AND (`t2`.`Operation` > `t1`.`Operation`)
AND (`t2`.`Operation` < (`t1`.`Operation` + 11)))))
LEFT JOIN `workcenters` `wc` ON ((`wc`.`WorkCenter` = `t1`.`WorkCenter`)))
LEFT JOIN `workorderoperationconfirmations` `wooc` ON (((`wooc`.`Order` = `t1`.`Order`)
AND (`wooc`.`Operation` = `t1`.`Operation`))))
WHERE
((`t1`.`LatestStartDate` <= CAST(`t1`.`ImportedOn` AS DATE))
AND (`t1`.`ImportedOn` = (SELECT
MAX(`t1`.`ImportedOn`)
FROM
`workorderoperationschedule` `t1`))
AND (`t2`.`ImportedOn` = (SELECT
MAX(`t1`.`ImportedOn`)
FROM
`workorderoperationschedule` `t1`)))
ORDER BY `Status` DESC , `t1`.`WorkCenter` , `t2`.`LatestStartDate` , `t2`.`LatestStartTime`
My challenge is that sometimes t2 will not have a value, which is expected, however, i think MySQL is not returning those rows when t2 has not match. I thought a left join would return all values from t1 and only the values from t2 that match but that is not happening