Puede usar COALESCE
:
ORDER BY COALESCE(dtModified, dtPosted)
Otra opción es usar la función específica de MySQL IFNULL
en lugar de COALESCE
.
Pruebas en MySQL:
CREATE TABLE table1 (dtModified DATETIME NULL, dtPosted DATETIME NOT NULL);
INSERT INTO table1 (dtModified, dtPosted) VALUES
('2010-07-31 10:00:00', '2010-07-30 10:00:00'),
(NULL , '2010-07-31 09:00:00'),
('2010-07-31 08:00:00', '2010-07-30 10:00:00');
SELECT dtModified, dtPosted
FROM table1
ORDER BY COALESCE(dtModified, dtPosted)
Resultados:
dtModified dtPosted
2010-07-31 08:00:00 2010-07-30 10:00:00
NULL 2010-07-31 09:00:00
2010-07-31 10:00:00 2010-07-30 10:00:00