I have the following query in my system:
SELECT
DISTINCT ON(consultant_profiles.id)
consultant_profiles.id,
(
array_remove(array_agg(DISTINCT(function_experiences.experience)), NULL) ||
array_remove(array_agg(DISTINCT(sellable_project_function_experiences.experience)), NULL)
) AS function_experiences
FROM
consultant_profiles
LEFT OUTER JOIN
consultant_backgrounds ON consultant_backgrounds.consultant_profile_id = consultant_profiles.id
LEFT OUTER JOIN
function_experiences ON function_experiences.consultant_background_id = consultant_backgrounds.id
LEFT OUTER JOIN
sellable_projects ON sellable_projects.consultant_profile_id = consultant_profiles.id
LEFT OUTER JOIN
sellable_project_function_experiences ON sellable_project_function_experiences.sellable_project_id = sellable_projects.id
GROUP BY
consultant_profiles.id;
The problem is that function_experiences
column can have a duplicated values. I tried to use DISTINCT
method but it is not working.
Is there any way of doing that in PostgreSQL?