show mysql rows in one column

show mysql rows in one column

Using MySQL, I can list the category but want rows to transpose in single column comma separated.

select category_name from categories

Result:
Rock
POP
Jazz
Desired Result:
Rock, POP,Jazz
Solution:
You can achive this by using group_concat function in mysql.

select group_concat(category_name separator ', ') from categories;

 
Reference:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *