Skip to content Skip to sidebar Skip to footer

Is It Possible To Get The List Of Rows Grouped Together By A Column Name In Mysql?

In my database, I have a table called 'results' with four columns (name,device,passed,failed). Suppose if there are 4 rows in the table as below. name device passed failed tes

Solution 1:

You need concatenation functions like CONCAT_WS() and CONCAT to concatenate the columns of each row and then aggregation with GROUP_CONCAT() for each name:

SELECT CONCAT('[', GROUP_CONCAT(CONCAT('(', CONCAT_WS(',', name, device, passed, failed), ')')), ']') ASresultFROM results
GROUPBY name

See the demo.

Solution 2:

SELECT GROUP_CONCAT('(',name,',',device,',',passed,',',failed,')') FROM results groupby name;

Post a Comment for "Is It Possible To Get The List Of Rows Grouped Together By A Column Name In Mysql?"