I have a situation where I have 2 tables 'users' and 'roles' table where they are related to each other by many to many relationship, many to many relationship stored in the 3rd table called 'UserRoles'. I want to write a query to show distinct users but show all the roles associated with a particular user in one single row.
For example, the 3 tables as follows:
users
UserName UserId
test11 000_1
test12 000_2
test13 000_3
test14 000_5
roles
Role Name Role ID
Admin 100_1
superuser 100_2
reader 100_3
writer 100_4
UserRoles
RoleID UserID
100_1 000_1
100_2 000_1
100_3 000_1
100_2 000_2
100_3 000_2
100_4 000_2
100_3 000_3
100_4 000_3
100_1 000_5
100_2 000_5
100_3 000_5
100_4 000_5
so how can I write a query that displays a row as below with roles separated with semicolons for every users?
UserName Role Name
test11 Admin;superuser;reader