SELECT CONCAT("Line ", line_n, " ", GROUP_CONCAT(word ORDER BY word_position SEPARATOR " ")) FROM words GROUP BY line_n ORDER BY line_n;