Group_CONCAT() Function is used to concatenate data from multiple rows into one field.
Have a look at the below example:
Let us have a table say, Employee, here Emp_id, Name, Skill are column names.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | +------------+--------------------+----------------+ | Emp_id | Name | Skill | +------------+--------------------+----------------+ | 1 | Praveen | Accounting | | 2 | Saroj | PHP | | 3 | Avinash | UI | | 4 | Mastan |.Net | | 5 | Nagesh |.Net | | 1 | Praveen | Staffing | | 2 | Saroj | mySQL | | 3 | Avinash | UX | | 4 | Mastan | SQL | | 4 | Mastan | Angular | +------------+--------------------+----------------+ |
Let’s run this query
1 2 3 | SELECT Emp_id, Name, GROUP_CONCAT ( skill) as "skills" FROM employee group by Emp_id; |
Output:–
1 2 3 4 5 6 7 8 9 | +------------+--------------------+--------------------------+ | Emp_id | Name | Skills | +------------+--------------------+--------------------------+ | 1 | Praveen | Accounting, Staffing | | 2 | Saroj | PHP,mySQL | | 3 | Avinash | UI,UX | | 4 | Mastan |.Net,SQL,Angular | | 5 | Nagesh |.Net | +------------+--------------------+--------------------------+ |