Brug COALESCE
i stedet:
SELECT
e.id,
c.name,
e.location,
e.designation,
e.time_period_from,
e.time_period_to,
DATEDIFF(COALESCE(e.time_period_to, NOW()), e.time_period_from) AS tenure_in_days
FROM employment e
LEFT JOIN company c ON (c.id = e.company_id)
LIMIT 0, 10
Jeg gætter på, at du ville have DATEDIFF(e.time_period_to, e.time_period_from)
.
Bruger LIMIT
uden eksplicit ORDER BY
kan returnere resultat afhængig af udførelsesplan.