MySQL – How to Combine Multiple Rows with Select

MySQLselect

I have a database where there's a description text stored but the description text itself is broken up into separate rows based on the text itself.

For example:

|ID  |Row  |Text                  |
-----------------------------------
|1   |1    |The cat went to the st|
|1   |2    |ore and bought some ca|
|1   |3    |tnip.                 |
|2   |1    |The dog didn't like to|
|2   |2    |drink water.          |
|3   |1    |It's cold outside     |

How would I write a select query so that all of the rows in the Text column are combined into a single result based on the ID column and ordered according to the Row column?

Best Answer

It's quite simple using GROUP_CONCAT():

select group_concat(txt order by roooow SEPARATOR '')
from story
group by id
order by roooow;

By the way, row and text are bad names for columns, as they are reserved keywords.