I have a DATETIME value “some_date” that can be null in my database. When I try the following query it returns nothing for those rows with date is null:
SELECT *
FROM tabel
WHERE DATE_ADD(some_date, INTERVAL some_seconds SECOND) < NOW()
Can I edit this query so that the DATE_ADD() will produce a DATE even when some_date is null?
You could use COALESCE to convert the NULL dates to something else, for example:
COALESCE returns its first non-NULL argument:
So you’d just need to decide which date you wanted to use in place of a NULL
some_date.If your replacement for a NULL
some_dateis going to be far enough into the past that the test will always pass then you could use:and if it will always fail, then: