Alexander Averchenko
Alexander Averchenko

Reputation: 113

How to group all string values to one cell in MySQL?

Let's say i have entry's like this.

Projects Persons
Project1 Person1
Project1 Person2
Project1 Person3
Project2 Person1

And i need an output like this:

Project1 Person1,Preson2,Person3
Project2 Person1

How can i do this using mySql?

Upvotes: 0

Views: 38

Answers (1)

Svperstar
Svperstar

Reputation: 497

try this:

SELECT Projects,
  GROUP_CONCAT(DISTINCT Persons
  ORDER BY Persons SEPARATOR ',')
  FROM <your_table_name>
  GROUP BY Projects;

Upvotes: 1

Related Questions