0

I have a table structured this way:

BUSINESS NAME        CATEGORY 
ABC Inc.             Pipes 
ABC Inc.             Plumbing 
Joe's Plumbing       Plumbing 
Joe's Plumbing       Emergency 

I want to regroup categories in the same row, separated by a character: I would then get:

ABC Inc.              Pipes,Plumbing 
Joe's Plumbing        Plumbing,Emergency 

How do I do this ?

Thanks !

TobyLL
  • 2,098
  • 2
  • 17
  • 23

2 Answers2

0

i cant get proper table name and its fields but you should try like below:

select GROUP_CONCAT(BUSINESS NAME) as "Business Name",CATEGORY from table_name group by CATEGORY;
Dharmesh patel
  • 654
  • 1
  • 12
  • 23
0

You can use group_concat function for this.

Make sure you have group_concat_max_len set properly for large data-set in the group_concat

select
group_concat(distinct business_name order by business_name) as business_name,
category 
from your_table
group by category;
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63