1. Are you looking for something like :
FROM Table1 t1
INNER JOIN CodePairs c1
ON (c1.Code1 = t1.Code
OR c1.Code2 = t1.Code)
GROUP BY Id
HAVING COUNT(DISTINCT Code) >= 2
2. I am not sure if I understood your narrative or not. Are you referring to
a "comparison" of columns along the lines of :
WHERE c2.Division = COALESCE(NULLIF(t1.Division, 0), c2.Division)
AND c2.SubDivision = COALESCE(NULLIF(t1.SubDivision, 0), c2.SubDivision))
AND c2.Section = COALESCE(NULLIF(t1.Section, 0), c2.Section)
In any case, I stringly suspect that the tables are not designed correctly.
It looks like a cooked-up structure which is forced to ...