I need a MySQL conditional ORDER BY statement for a datetime field. I have a table with posts which I would like to order in the following way: all future posts
i would use an union all, tricks in order by can't use index and is slower.
SELECT * FROM
((SELECT
1 AS a, @rownum:=@rownum+1 B, post_status, post_date, post_title
FROM
wp_posts, (SELECT @rownum:=0) r
WHERE
post_status='publish'
ORDER BY
post_date DESC)
UNION ALL
(SELECT
2 AS a, @rownum:=@rownum+1 B, post_status, post_date, post_title
FROM
wp_posts, (SELECT @rownum:=0) r2
WHERE
post_status='future'
ORDER BY
post_date)) ORDER BY A,B;