Home > Net >  How do I make repeated data show only once in inner join query Postgres?
How do I make repeated data show only once in inner join query Postgres?

Time:10-08

I did an inner join in Postgres. I want the incoming json data to not contain repeated data. How can I update my query?

this query

SELECT academy_projects.project_name,
array_agg( academy_technology.name) as academy_technology,
array_agg( academy_users.user_name) as academy_users,
array_agg( academy_classes.name) as academy_classes,

FROM academy_projects
inner join academy_technology  on academy_technology.id=any(academy_projects.technology_id)
inner join academy_users  on academy_users.user_id = any(academy_projects.user_id)
inner join academy_classes  on academy_classes.id = any(academy_projects.classes_id)  
group by academy_projects.project_name

database raw

If the values ​​in the json data are the same, I want it to return only one, how should I edit my query?

for example academy_classes column should be like this:

{insan,scooter}

CodePudding user response:

Use DISTINCT: array_agg( DISTINCT academy_technology.name)

  • Related