Use of Group_Concat in MySql

Posted by vishalneeraj-24503 under Others category on | Points: 40 | Views : 1599
Sometimes we need to have Comma-Separated values from table.
In MySql,it' very very easy. With Group_Concat in-built MySql function,we can achieve such things.

For ex:-
Suppose,i have employee_master table in which employee_id is an auto-generated column.
I want to have comma-separated employee_id,then i will do like:-

Select Group_Concat(employee_id) as 'Employee Id' from Employee_Master where Status = 'AA';

Output will be:-

Also we can use order by clause inside Group_Concat function:-

Select Group_Concat(employee_id order by employee_id) as 'Employee Id' from Employee_Master where Status = 'AA';

Group_Concat function adds Comma(,) separator as default but we can take our own separator as anything with the help of Separator inside Group_Concat as shown

Select Group_Concat(employee_id order by employee_id SEPARATOR ';') from Employee_Master where Status = 'AA';

Output will be:-

So we can have own choice with Group_Concat function in MySql DB.

Comments or Responses

Login to post response