diff --git a/reportbuilder/classes/local/helpers/user_profile_fields.php b/reportbuilder/classes/local/helpers/user_profile_fields.php index bed8d1e9c7d..66f15b83eb9 100644 --- a/reportbuilder/classes/local/helpers/user_profile_fields.php +++ b/reportbuilder/classes/local/helpers/user_profile_fields.php @@ -115,11 +115,21 @@ class user_profile_fields { /** * Generate table alias for given profile field * + * The entity name is used to ensure the alias differs when the entity is used multiple times within the same report, each + * having their own table alias/join + * * @param profile_field_base $profilefield * @return string */ private function get_table_alias(profile_field_base $profilefield): string { - return "upfs{$profilefield->fieldid}"; + static $aliases = []; + + $aliaskey = "{$this->entityname}_{$profilefield->fieldid}"; + if (!array_key_exists($aliaskey, $aliases)) { + $aliases[$aliaskey] = database::generate_alias(); + } + + return $aliases[$aliaskey]; } /**