Fixes the query when merging different identitytypes with the same name.