Sample Header Ad - 728x90

Group_concat with joining multiple tables

0 votes
2 answers
2113 views
I have the following scheme users: researches: researchyear: uid | name rid| titleAr rid | uid | ---+-------- ---+------------ --------+----------+ 1 | Peter 1 | Tennis 1 | 1 | 2 | Alice 2 | Football 1 | 2 | 3 | Bob 3 | Basketball 2 | 3 | 3 | 1 | 3 | 3 | 3 | 2 | I would like to get a research with its researchers (users) by specific researcher_Id(uid), i.e when I set user id (1,3 or 2) I would like to get the same result. id |titleAr | users_ids | users_names ---+-------+-----------+---------------------------- 3 |Basketball | 1,3,2 | Peter,Bob,Alice I've tried the following query where I can get every research with its researchers (users): SELECT r.rId, r.titleAr, Group_concat(u.userId ) users_ids , Group_concat(u.name ) users_names FROM research r LEFT JOIN researchyear ry ON r.rId = ry.rId LEFT JOIN users u ON ry.uId = u.userId GROUP BY r.rId, r.titleAr How can I get it for one user?
Asked by Ali A. Jalil (113 rep)
Aug 25, 2021, 06:55 AM
Last activity: Aug 27, 2021, 10:04 AM