SELECT *, ( CASE WHEN m.id IN ( SELECT id FROM table_b WHERE xxxxxx ) THEN 'Y' ELSE 'N' END ) AS status FROM table_a