In MySQL How do I SELECT all ids from rows with a similar value

Viewed 4533

I want to pull all the unique IDs for particular rows with the same username and then display each result as a row.

For example...

Here's my table:

+----+------+
| id | name |
+----+------+
| 1  | Joe  |
| 2  | Amy  |
| 3  | Joe  |
| 4  | Amy  |
| 5  | Joe  |
| 6  | Amy  |
+----+------+

Here's the result I want:

+------+-------+
| name | ids   |
+------+-------+
| Joe  | 1,3,5 |
| Amy  | 2,4,6 |
+------+-------+

How do I pull this result in MySQL?

3 Answers
Related