Fix ending with OR query and a join