code, (select k.Coa_Group_Id from Mk_Coa_Groups k where k.Company_Id = d.Company_Id and exists (select 1 from Mk_Company_Coa_Group_Templates f where f.Template_Id = 2 and f.Coa_Group_Id = t.Coa_Group_Id and f.Code = k.Code)) Company_Coa_Group_Id