3

I have a table with a structure like:

| id | textfield | text_group | 
| 1  | yes       | 123        | 
| 2  | y         | 123        | 
| 3  | no        | abc        | 
| 4  | n         | abc        | 

I'd like to return all records, but such that I get:

| colA  | text_group | 
| yes y | 123        |
| no n  | abc        |

Is this possible simply with a query, or will I need to use some programming to format it as such? I would have done a group by, but then I lose the information in result ColA

halfer
  • 19,471
  • 17
  • 87
  • 173
NinjaCat
  • 9,701
  • 9
  • 43
  • 63

2 Answers2

4

The group_concat aggregate function should do the trick:

SELECT   group_concat (textfield SEPARATOR ' ') AS colA, text_group
FROM     my_table
GROUP BY text_group
Mureinik
  • 277,661
  • 50
  • 283
  • 320
2

Use GROUP_CONCAT :

SELECT text_group
     , GROUP_CONCAT(textfield SEPARATOR ' ') AS colA
FROM table
GROUP BY text_group
potashin
  • 43,297
  • 11
  • 81
  • 105