I\'ve got a database which contains lots of data. I would like to select all data, but Group by one column.
So for example:
column a | column b
examp
I think you can get what you want using group_concat()
:
select a, group_concat(b)
from t
group by a;
This will create a list of "b"s for each a. In your example:
example apple,pear,orange,strawberry
You can change the separator using the SEPARATOR
keyword.
EDIT:
You can use group_concat()
multiple times:
select a, group_concat(b) as bs, group_concat(c) as cs
from t
group by a;
Or, combine it with concat()
:
select a, group_concat(concat(b, ':', 'c')) as bcs
from t
group by a;