I got a strange condition in Mysql coalesce function:
select start_date, end_date, COALESCE(end_date, start_date)
from log where log_id = 8999134
returns: 2011-02-09 23:00:38, NULL, NULL
Anyone has any idea why coalsce is not working as it should ?
Edit:
After some research I decided to try the query in MYSQL workbench and saw that the tool I was using to access the database was incorrectly returning null when the field had end_date = 0000-00-00 00:00:00. Yet the problem got even more strange. The result above is already a debug. The first query was:
select id, start_date, COALESCE(end_date, start_date)
from log where end_date is null
from where I debugged:
select id, start_date, end_date, end_date is null
from log where end_date is null
and the result was: 2011-02-09 23:00:38, 0000-00-00 00:00:00, 0
This is result's first line, but got equal results to the other lines. Why the end_date is NULL for where and not to coalesce ?
the datatype for both fields is datetime