To join several rows into one string per group in MySQL, use GROUP_CONCAT() with GROUP BY . The order and the separator go inside the brackets: GROUP_CONCAT(subject ORDER BY subject SEPARATOR ', ') . Add DISTINCT straight after the opening bracket to drop duplicates.

Source: [Dev.to](https://dev.to/mfaysaldev/mysql-groupconcat-with-order-by-separator-and-distinct-tested-on-84-5dke)

Sponsored