Hi

I have a mysql tables shown below:

table_structure.png

I need to build a query to select all groupnames a user belongs to in a single field seperated by ','

e.g. I wanted to following results

id   fname   lname      groups
1    connor  Faulkner   group_one,group_two
2    Maisie  Yates      group_four,group_three

Just like that...

I have done the following but not sure how to get groups in one column...

Select u.*, g.name from tbl_user u
Left Join tbl_group_member gm on gm.userid = u.id
Left Join tbl_group g on gm.groupid = g.id

Not sure what I need to do next. The query above will not give list of groups in one row column..

If you can direct me to function/example/any relating help then I would much appriciate it.

Thank you in advance..

I think group_concat will work

Thanks anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.