SELECT *
FROM (
FROM (
SELECT t.task_name, t.status AS task_status, coalesce( r.task_ref_id, 999 ) AS task_ref_id, coalesce( r.status, 999 ) AS ref_status
FROM map_task t
LEFT JOIN map_task_ref r ON r.task_id = t.task_id
) AS t1
WHERE task_status =1