COALESCE two dates returns binary?

前端 未结 2 1473
醉话见心
醉话见心 2021-01-21 04:27

Why does COALESCE(date1,date2) return Blob(binary)? Both columns are of type DATETIME.

Here\'s the complete sql query:

<         


        
2条回答
  •  无人及你
    2021-01-21 05:04

    I still don't know why this happens in MySql Workbench (and also MS Visual Studio). But i have found a workaround. I just cast the result to DATETIME and it works as expected:

    SELECT CAST(COALESCE( last_modified, date_purchased )AS DATETIME)As LastModifiedOrPurchased
    FROM Orders
    ORDER BY COALESCE( last_modified, date_purchased )DESC
    LIMIT 1;
    

    Edit: as Jack has commented, IFNULL works also:

    SELECT IFNULL( last_modified, date_purchased )As LastModifiedOrPurchased
    FROM Orders
    ORDER BY IFNULL( last_modified, date_purchased )DESC
    LIMIT 1;
    

提交回复
热议问题