Skip to content
Advertisement

Filtering out duplicates yet showing non-duplicate rows from another column in one row

I have a table with multiple duplicate values. What I’d like to do is use some sort of SELECT query that will filter the duplicates by name and yet keep all the appropriate values from the “expertise” column and show them next to each other in one row separated by a coma.

In other words I want to turn a table that looks like this:

Into This:

I’m using PostgreSQL as my database.

Can anyone help? Haven’t done queries for so long, and couldn’t find a similar question that addresses this.

Advertisement

Answer

Use aggregation:

The above uses string_agg() because the result looks like a string. I would advise you to use arrays instead:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement