Você pode usar
COALESCE
:ORDER BY COALESCE(dtModified, dtPosted)
Outra opção é usar a função específica do MySQL
IFNULL
em vez de COALESCE
. Testando no 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