basically:select hcc, diagnosisfrom hcc_diagnosis_tablewhere hcc in (8, 9, 10) and not exists (select 1 from hcc_diagnosis_table where hcc = 7) OR hcc not in (8,9,10)
That's a basic idea. OTOH if you had a table that had columns:hcc hcc_to_exclude7 87 97 10you could write (untested, but food for thought)select hcc, diagnosisfrom hcc_diagnosis_table hleft join hcc_exclusion_table x1 on h.hcc = x1.hccleft join hcc_exclusion_table x2 on h.hcc = x2.hcc_to_exclude and x1.hcc = x2.hccwhere x1.hcc is null or x2.hcc_to_exclude is null