Using MySQL
, I can do something like:
SELECT hobbies FROM peoples_hobbies WHERE person_id = 5;
My Output:
shopping
fishing
coding
but instead I just want 1 row, 1 col:
Expected Output:
shopping, fishing, coding
The reason is that I'm selecting multiple values from multiple tables, and after all the joins I've got a lot more rows than I'd like.
I've looked for a function on MySQL Doc and it doesn't look like the CONCAT
or CONCAT_WS
functions accept result sets, so does anyone here know how to do this?
In my case I had a row of Ids, and it was neccessary to cast it to char, otherwise, the result was encoded into binary format :
Try this:
I had a more complicated query, and found that I had to use
GROUP_CONCAT
in an outer query to get it to work:Original Query:
Imploded:
Hope this might help someone.
Use MySQL(5.6.13) session variable and assignment operator like the following
then you can get