Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sort by MAX of two dates

0 views
Skip to first unread message

Melih Onvural

unread,
Jul 22, 2008, 5:05:58 PM7/22/08
to
We have a creation date, and a modified date. I was trying to sort by
the maximum of either date. As an example, everything has a creation
date, but only some have modified dates. I want to use the creation
date to sort, unless it has a modified date, and then I want to use
that instead. Is there anyway to do this? Thanks.

--
Melih

strawberry

unread,
Jul 22, 2008, 7:17:46 PM7/22/08
to

Assuming modified has a default value of NULL...

ORDER BY COALESCE(date_modified,date_created)

sonic-news.com webmaster

unread,
Jul 25, 2008, 8:38:32 PM7/25/08
to
Why don't you set the modified date equal to the creation date if it has
never been modified, and just sort on that? Sure, you could sort on a
function, but I suspect you would lose some efficiency. Be careful with
GREATEST() because it returns null if any argument is null.
0 new messages