I have a table with an id and 2 datetime fields with over 2000 rows:
Example:
id created_at updated_at
1 2015-07-07 13:39:38 NULL
2 2015-08-06 14:09:14 2015-11-18 10:20:55
3 2015-08-07 11:01:48 2015-11-12 16:43:11
...
How can i get a list sorted by the most recent datetime?
Order by updated_at DESC, created_at DESC
gives me a wrong result. It orders by updated_at
and then by created_at
and doesn't give me the expected result.
I also tried several solutions with CASE WHEN
, but it didn't work for me.
Correct sorted list for the example:
id created_at updated_at
1 2015-08-06 14:09:14 2015-11-18 10:20:55
2 2015-08-07 11:01:48 2015-11-12 16:43:11
3 2015-07-07 13:39:38 NULL
...