Problem: I’d like to combine the results of a subquery as a text field, with the results separated by a comma (or any symbol really), into the results of the main query.
Example:
Table 1:
+----------+---------+
| user_ID | user |
+----------+---------+
| 1 | Smith |
+----------+---------+
| 2 | Jones |
+----------+---------+
Table 1:
+----------+---------+
| user_ID | roles |
+----------+---------+
| 1 | Admin |
+----------+---------+
| 2 | Staff |
+----------+---------+
| 2 | Admin |
+----------+---------+
| 2 | Super |
+----------+---------+
| 1 | Other |
+----------+---------+
So the result would be:
+----------+---------+----------------------------+
| user_ID | user | roles |
+----------+---------+----------------------------+
| 1 | Smith | Admin, Other |
+----------+---------+----------------------------+
| 2 | Jones | Staff, Admin, Super |
+----------+---------+----------------------------+
Any help would be greatly appreciated.
Try this:
Check the
GROUP_CONCATdocumentation for more info.