Fix self-join errors