I’ve got a query:
SELECT
taskDeadline,
subtasksDeadline,
REPLACE(
LEAST(
COALESCE(t.deadline, 2147483647),
COALESCE(sub.deadline, 2147483647)
), 2147483647, NULL
) AS Deadline
FROM
tasks t
LEFT OUTER JOIN subtasks sub ON sub.task_id = t.id
This produces a result like this:
taskDeadline | subtasksDeadline | Deadline
1338501600 | 1333058400 | 1333058400
1334268000 | NULL | 1334268000
NULL | 1328050800 | 1328050800
NULL | NULL | NULL
1353798000 | 0 | 0
0 | 1353798000 | 0
I’m almost there. I’ve used 2147483647 as the maximum value of the data type (Mysql INT), the only problem I still have, is that if I’ve two values of which one is 0, I want to get the other value. I’ve spend some time but cannot get there. Can somebody shed a light on this?
Or just add NULLIF to your existing COALESCE –