factor out the subset code for left and inner joins