I am trying to get the role_name from role table using the roles column in my individual table.
This is what's inside my role table:
role_id | role_name
____________________
1 |Participant
2 |Respondent
3 |Survey Previewer
4 |Coach
5 |Faculty Viewer
6 |Hr
7 |Client Admin
I am trying to left join the role_name in my individual table using values from roles column, this is my roles column inside individual table, and these numbers are from inputted using role_id:
roles
______
1, 3 |
1, 4, 5, 7 |
2, 4, 5 |
I tried using this query:
export const getAllIndividuals = (result) => {
db.query(
"SELECT (GROUP_CONCAT(role.role_name SEPARATOR',')) AS _roles_name, individual.* FROM
individual LEFT JOIN role ON role.role_id = individual.roles GROUP BY individual.ind_id",
(err, results) => {
if (err) {
console.log(err);
result(err, null);
} else {
result(null, results);
}
}
);
};
but this query only gives me the result of the first number in my roles column, you can see it in this example :
How can I return all the role_name I need based on my roles column?