How will you get the comma separated values for a column in a MySQL Group query?

MySQL provides a function GROUP_CONCAT() that returns the concatenated non-null values for a group in GROUP BY query.

Eg. If there is a Employee table with Dept column. We can run a GROUP BY query on Dept column and get the list employees name in a comma-separated format.

SELECT DEPT, GROUP_CONCAT(EMPLOYEE_NAME)
FROM EMPLOYEE
GROUP BY DEPT

It will return
Finance: John, George, Smith, Julie
Marketing: Jim, Jack, Jasmine

Read the full book at www.amazon.com
Posted in MySQL, MySQL Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*