4

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,824
  • 17
  • 99
  • 186
NinjaCat
  • 9,974
  • 9
  • 44
  • 64

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
  • 297,002
  • 52
  • 306
  • 350
2

Use GROUP_CONCAT :

SELECT text_group
     , GROUP_CONCAT(textfield SEPARATOR ' ') AS colA
FROM table
GROUP BY text_group
potashin
  • 44,205
  • 11
  • 83
  • 107