var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: how to order by bigger of 2 columns (solved)
I have a simple table
posts(text, created_at, commented_at)
Is it possible to find all posts and order them by the larger value of created_at or commented_at? Something like
"select * from posts order by max(created_at, commented_at)"
Last edited by sthapit; 08-13-09 at 09:43.
You might want to make sure it's working properly if any of the two dates can be NULL
ORDER BY CASE
WHEN created_at > commented_at THEN created_at
no need to check for NULL, the function takes care of that
...ORDER BY GREATEST( created_at , commented_at )
I always forget about the non-standard functions
Originally Posted by r937
that works perfectly thanks!
out of curiosity, is there a similar function to greatest for mysql?
yes, there is
Originally Posted by sthapit