symfony2 doctrine select IFNULL symfony2 doctrine select IFNULL symfony symfony

symfony2 doctrine select IFNULL


Use COALESCE instead of IFNULL like this

$fields = array('COALESCE(s2.id,s1.id) AS effectiveID','COALESCE(s2.status, s1.status) AS effectiveStatus', 'COALESCE(s2.user_id, s1.user_id) as effectiveUser','COALESCE(s2.likes_count, s1.likes_count) as effectiveLikesCount');

COALESCE return the first value not null in the list, so if A is null and B not null, then COALESCE(A,B) will return B.