MySQL - query to return CSV in a field?

Posted by StackOverflowNewbie on Stack Overflow See other posts from Stack Overflow or by StackOverflowNewbie
Published on 2011-11-27T09:30:28Z Indexed on 2011/11/27 9:50 UTC
Read the original article Hit count: 268

Filed under:
|

Assume I have the following tables:

TABLE: foo
- foo_id (PK)

TABLE: tag
- tag_id (PK)
- name

TABLE: foo_tag
- foo_tag_id (PK)
- foo_id (FK)
- tag_id (FK)

How do I query this so that I get a result like this:

==========================
| foo_id | tags          |
==========================
| 1      | foo, bar      |
| 2      | foo           |
| 3      | bar           |
--------------------------

Basically, I need all of foo's tags in one column, comma separated. Possible in MySQL?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about database-query