Merging MySQL row entries into a single row

Posted by Derrick on Stack Overflow See other posts from Stack Overflow or by Derrick
Published on 2010-05-03T21:51:30Z Indexed on 2010/05/04 5:38 UTC
Read the original article Hit count: 276

Filed under:
|

I've got two tables, one for listings and another representing a list of tags for the listings table.

In the listings table the tag ids are stored in a field called tags as 1-2-3-. This has worked out very well for me (regular expressions and joins to separate and display the data), but I now need to pull the titles of those tags into a single row. See below.

listings table
id    tags
1     1-2-3-
2     4-5-6-


tags table
id    title
1     pig
2     dog
3     cat
4     mouse
5     elephant
6     duck

And what I need to produce out of the listings table is:

id     tags
2      mouse, elephant, duck

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query