Can you help me cause all the records in the “preference” table to become a string inside the p.data returned result?
I could only think of CONCAT, but my inner join only selects 1 record.
Example Query
SELECT
u.userid,
p.data
FROM user u
INNER JOIN preference p ON (
p.userid = u.userid
)
WHERE u.userid = 1
Desired Output
userid | data
--------------
1 | 1,2,3,4,5
2 | 1,2,3,4
3 | 1,2,3
MySQL’s
GROUP_CONCAT()performs exactly this function:You only get one row back because of your
WHEREclause. Remove theWHEREclause to return rows for all users. And switch it to aLEFT JOINif you want to return users having no related rows in thepreferencetable.