'How to combine all words in a column into 1 sentence using a simple MySQL Query? [duplicate]
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GustaMatos0 |
