Q:

How to select record with highest date found in two datetime columns?

I am trying to return the record of in table that has the highest date in two separate DATETIME columns.
For example:
--------------------------------------------------------------
| ID |       DATE1       |       DATE2          |  OTHERDATA |
--------------------------------------------------------------
|  1 |2016-02-16 17:14:10| NULL                 |     3      |
--------------------------------------------------------------
|  2 |2016-02-29 10:14:51| 2016-03-03 12:43:39  |     3      |
--------------------------------------------------------------
|  3 |2016-03-03 12:43:39| 2016-03-10 01:00:00  |     3      |
--------------------------------------------------------------

MYSQL query I have to far:
SELECT *, GREATEST(COALESCE(DATE1,0), 
     COALESCE(DATE2,0)) 
FROM Table 
WHERE OTHERDATA = 3
GROUP BY OTHERDATA;

I am expecting this query to return ID 3 but instead it returns ID 1. I am assuming it has something to do with the NULL but I thought COALESCE would handle that? Any ideas?

A:

SELECT *
   FROM table
 WHERE otherdata = 3
 ORDER
    BY GREATEST(COALESCE(DATE1,0), 
 COALESCE(DATE2,0)) DESC
 LIMIT 1

