I stedet for COALESCE(a.addressid,0) AS addressexists
, brug CASE
:
CASE WHEN a.addressid IS NOT NULL
THEN 1
ELSE 0
END AS addressexists
eller det enklere:
(a.addressid IS NOT NULL) AS addressexists
Dette virker fordi TRUE
vises som 1
i MySQL og FALSE
som 0
.