Skip to content
Advertisement

PHP MySQL Grouping Issue

If I have a table with the following data in MySQL:

JavaScript

I need it to look like this:

JavaScript

I’ve tried:

JavaScript

Which does not give me the results I want. Any help would be greatly appreciated.

SQL Fiddle

Thank you

Advertisement

Answer

You need to use GROUP_CONCAT to aggregate your values, and based on your sample data you want to group by the first word in the name, so you can use SUBSTRING_INDEX to extract that. To deal with possible / in the name as a separator instead of space, you can REPLACE them:

JavaScript

Output:

JavaScript

Demo on SQLFiddle

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement