Make joins work when the same table occurs 3 times