-2

how to get from this:

id   foo_name
1        A
2        A
3        A
4        A
5        B
6        B
7        B
8        A
9        B
10       A

to this: 1 row only

foo_names
A,B

I tried using GROUP_CONCAT but it give me this:

A,A,A,A,A,A,A,

B,B,B,B

woninana
  • 3,171
  • 9
  • 39
  • 65

2 Answers2

0

You can use:

select group_concat(distinct foo_name) as foo_names
from t;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
0

With group_concat():

select group_concat(distinct foo_name order by foo_name) foo_names
from tablename

See the demo.

forpas
  • 145,388
  • 9
  • 31
  • 69