SELECT id FROM `ohrm_performance_competency` as c LEFT JOIN `ohrm_performance_title_competency` as jc ON c.id = jc.employee_competency_id WHERE c.appraisal_id IS NULL AND c.deleted_at IS NULL AND jc.job_title_id = #jobTitleId# UNION SELECT id FROM `ohrm_performance_competency`as c1 WHERE c1.appraisal_id = #appraisalId# AND c1.deleted_at IS NULL