i have table company data is :
id | name | email
1 | abc | any@any.com
2 | xyz | as@as.com
other table of category data is :
id | name
1 | cat1
2 | cat2
3 | cat3
and joined table of both category and company is join_cat_company
category_id | company_id | main
1 | 1| 1
2 | 1| 0
3 | 1| 0
2 | 2| 1
1 | 2| 0
3 | 2| 0
in joined table main is use for main category
i want result like :
company_name | category
abc | cat1,cat2,cat3
xyz | cat2,cat1,cat3
the main category must be fist of the category list
See it on sqlfiddle.
EDIT
Further to @lanzz’s excellent observation above, you could simply do:
See it on sqlfiddle.