Detta kan hanteras med sekventiell skanning av tabellen och med hjälp av MySQL-variabler. Du kan testa i (uppdaterad ) SQL-fiol :
SELECT date2
, dd
, DATE_FORMAT(dd, '%b %e, %Y') AS final_date
, date1_duplicate
, date1_was_null
FROM
( SELECT date2
, COALESCE( (date1 = @d OR date1 = @prev), FALSE)
AS date1_duplicate
, (date1 IS NULL) AS date1_was_null
, @d := CASE WHEN (date1 = @d OR date1 = @prev)
THEN date2
ELSE COALESCE(date1, date2)
END AS dd
, @prev := date1 AS pre
FROM tableX AS t
CROSS JOIN
( SELECT @d := DATE('1000-01-01')
, @prev := @d
) AS dummy
ORDER BY date2 ASC
) AS tmp
ORDER BY date2 DESC
;