-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,409
  • 9
  • 42
  • 66

2 Answers2

0

You can use:

select group_concat(distinct foo_name) as foo_names
from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

With group_concat():

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

See the demo.

forpas
  • 160,666
  • 10
  • 38
  • 76