getting a comma separated list in a MySQL Group By statement

If you are combining several rows in a MySQL query using a GROUP BY statement and still want to get a comma separated list of all the values of a particular column…

something like below:

Dataset:

ID           Marks

1                 20

2                 30

3                 40

 

Result Required:

IDs         Sum(Marks)

1,2,3          90

you should be using the GROUP_CONCAT function of MySQL. Check out more of it at MySQL official documentation

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>