What I'm trying to do is to find all matching IDs from two tables then combine multiple rows into one cell in the original table.
So I have these two tables. Table 1
+-----+-------+
| id | BS_ID |
+-----+-------+
| 999 | 12345 |
| 977 | 12347 |
| 955 | 12349 |
| 933 | 12351 |
+-----+-------+
Table 2
+-----+-------+------------+
| id | BS_ID | callstatus |
+-----+-------+------------+
| 999 | 12345 | noanswer |
| 999 | 12345 | contacted |
| 977 | 12347 | noanswer |
| 955 | 12349 | noanswer |
| 933 | 12351 | noanswer |
| 933 | 12351 | contacted |
+-----+-------+------------+
What I want to happen is find all matching rows in table 2 based on the id in table 1. Then copy the "callstatus" in all the matching rows and put it in one cell in table 1 like the one below:
+-----+-------+---------------------+
| id | BS_ID | callstatus |
+-----+-------+---------------------+
| 999 | 12345 | noanswer, contacted |
| 977 | 12347 | noanswer |
| 955 | 12349 | noanswer |
| 933 | 12351 | noanswer, contacted |
I have so far figured out how to count the instances in table 2 but I am stumped on how to copy the "callstatus" into that one cell in table 1.
SELECT table1.*
, (SELECT COUNT(*)
FROM table2
WHERE table2.id = table1.id) AS TOT
FROM table1