0

I have a table below:

words
'Hello'
'Big'
'World'

And I would like to return all these words into one sentence using a simple MySQL query. See below:

sentence
'Hello Big World. '

How do I return all words in a column into one sentence?

*Note that the column words can have any number of words in it. Not just 3.

1 Answers1

-2

You should use the GROUP_CONCAT() function. the syntax is:

SELECT col1, col2, ..., colN
GROUP_CONCAT ( [DISTINCT] col_name1 
[ORDER BY clause]  [SEPARATOR str_val] ) 
FROM table_name GROUP BY col_name2;

col1, col2, ...colN : Are the column names of the table.

col_name1: Column of the table whose values are concatenated into a single field for each group.

table_name: Name of table.

col_name2: Column of the table according to which grouping is done.

Source: https://www.geeksforgeeks.org/mysql-group_concat-function/

Further explanation there.