4

Given data such as

Type    Value
A       This
A       is
B       Will
A       a
B       this
A       test
B       work

I would like to end up with

Type    Value
A       This is a test
B       Will this work

Is this possible? Thanks!

Jimmy Johnson
  • 75
  • 1
  • 3

1 Answers1

4

Use GROUP_CONCAT().

SELECT Type, GROUP_CONCAT(Value SEPARATOR ' ') AS Value
FROM MyTable
GROUP BY Type;

Ensuring the words are concatenated in the order you want can be tricky, however. GROUP_CONCAT() has an ORDER BY clause (see the docs) but your example doesn't include any column that can be used to determine the order. Relying on the physical storage order isn't reliable.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828