I’n not sure what you are doing.
Sounds like you are doing an SQL join.
Why does the RRN matter?
If it’s so you can determine the XYCOD wouldn’t this statement do it?
Select count(*), a.XYCOD
from tablea a join tableb b
on a.XYCOD = b.XYCOD
group by XYCOD