SQL newbie here.
I am trying to return a table with a list of memberships that belong to each user. The data is in two tables, one a table of users with name and description, and the other table with one or more records for each user with the name and membership identifier:
USER TABLE
Name Description
------ -----------
User01 First User
User02 Second User
MEMBERSHIP TABLE
Name Membership
------ ----------
User01 Group01
User01 Group02
User02 Group01
User02 Group03
User02 Group05
So far the code I have returns one line for each membership the user has:
SELECT U.name, U.description, M.groupname
FROM user U, membership M
WHERE U.name = M.username
ORDER BY U.name
Name Description Membership
------ ----------- ----------
User01 First User Group01
User01 First User Group02
User02 Second User Group01
User02 Second User Group03
User02 Second User Group05
I want to return a list of users, followed by all the groups that user belongs to:
Name Description Membership
------ ----------- ----------
User01 First User Group01, Group02
User02 Second User Group01, Group03, Group05
How do I get this kind of result ?
Thank you !