Home > Software engineering >  How do I get one to many values in to one row in sql?
How do I get one to many values in to one row in sql?

Time:04-12

I am trying to set the following formated value to appear in one row. This is hard for me to explain as I do not know the right term. I am trying to do this in MySQL. I am not able to figure out how can I concatenate to side by side in one row, without duplicating.

enter image description here

Any guidance or help is highly appreciated.

Thank you.

CodePudding user response:

You can do it by using the GROUP_CONCAT function:

SELECT 
    Name,
    GROUP_CONCAT(Mark SEPARATOR ',') AS Marks
FROM 
    tab
GROUP BY 
    Name

Here's a fiddle: https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=4e73f6b00fe5a193a4fb5b43d4931658.

  • Related