I want to select a2.date if it’s there, but if it’s NULL I want to select a1.date (a2 is being left-joined). This:
SELECT a2.date OR a1.date
...
Simply returns a boolean result (as one would expect), how do I get the actual value of the non-null column though? (a2.date is preferred, but if it’s null then a1.date)
The ANSI means is to use COALESCE:
The MySQL native syntax is IFNULL:
Unlike COALESCE, IFNULL is not portable to other databases.
Another ANSI syntax, the CASE expression, is an option:
It requires more direction to work properly, but is more flexible if requirements change.