Member Avatar for jward50

Hi I am a bit rusty with SQL, not used it for about 8 years so would appreciate a bit of help.
I have three tables, normalised,

organisation, stores org_name and org_id
ativities stores activity_name and ativity_id
org_activity stores org_id and activity_id

I need to get a list that contains each organisation name distinctly along with a list of all the activities associated with it. Try as I might I just can't get my head round it, any pointers would be greatfully received.
Thanks
Julie

Recommended Answers

All 2 Replies

Mysql has a nifty function for it: group_concat
Like in

select org_name, group_concat(activity_name)
from organisation o, activities a, org_activity oa
where o.org_id=oa.org_id
and oa.activity_id=a.activity_id
group by o.org_id
;

(Code not tested)
Alternatively you may look at the various JOIN syntax varieties of MySQL.

Member Avatar for jward50

Wow thanks a million, I have never come across group_concat and it does the trick.
Thanks you so much for all your help

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.