2021年4月1日星期四

How do I remove duplicate attributes in a multivalue attribute in postgresql?

I am trying to select from my database movies and their associated genres in a comma separated list. Unfortunately there is one movie which has the attributes duplicated. How would I remove these just in my query?

select movies.title as title, string_agg(movie_genres.genre, ',') as genres  from movies join movie_genres on (movies.id=movie_genres.movie_id)  where movie_genres.genre != 'biography' and movie_genres.genre != 'documentary'  group by title  having count(genre) > 2  order by title asc, genres asc  
https://stackoverflow.com/questions/66913630/how-do-i-remove-duplicate-attributes-in-a-multivalue-attribute-in-postgresql April 02, 2021 at 10:06AM

没有评论:

发表评论