MySQL - Select Club Name and list all members in one query? -


  1. i have "clubs" table , "members" table
  2. i'd query return club name (clubs.name) , each member's nickname (members.nickname)

i can them using inner join,

select clubs.name `club name`, members.nickname `member handle` clubs inner join members on clubs.club_id = members.club_id 

but shows club.name field each member.nickname.

| club name   | member handle | -------------------------------    | club yellow | jim-bob       | | club yellow | clem          |  | club yellow | mustache pete | | club green  | ladyhawke     | | club green  | rosie         | 

is @ possible receive result so?

| club name   | member handle | -------------------------------    | club yellow | jim-bob       | |             | clem          |  |             | mustache pete | | club green  | ladyhawke     | |             | rosie         | 

thanks

no in mysql can not generate result this, need use application level it. can format data i.e. member-handle comma-separated values

select  clubs.name `club name`, group_concat(members.nickname) `member handle` clubs inner join members on clubs.club_id = members.club_id  group clubs.name 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -