SQL Group by - listing all rows by group?

Data such as

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

I would like to end with

 Type Value A This is a test B Will this work 

Is it possible? Thanks!

+4
source share
1 answer

Use GROUP_CONCAT () .

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

Ensuring word concatenation in the order you want can be difficult. GROUP_CONCAT() has an ORDER BY (see docs), but your example does not contain a column that can be used to determine the order. Reliance on storage order is not reliable.

+4
source

Source: https://habr.com/ru/post/1308070/


All Articles