【发布时间】:2011-01-06 22:42:07
【问题描述】:
我现在尝试了几乎所有我能解决的问题。到目前为止没有成功。但必须有一个解决方案,因为我不认为这个案子太特别了。我想我只是一个该死的初学者;-)我需要在 MySQL 中加入 union merge 或其他什么 ;-) 来解决以下问题...
CASE:三个表“posts”、“tagmap”和“tags”
tagmap 表存储所有 n-m 关系,即帖子的 id 和标签的 id
tags 表存储 tag_name 和 tag id
posts 表存储 post_title 和 post_id
posts post_id post_title
1 Charlie Chaplin Painting
tagmap id post_id tag_id
100 1 12
101 1 13
102 1 14
tags tag_id tag_name
12 Acryl
13 Chalk
14 Poster
我想要实现的是获得如下结果,即所有相关标签都合并在一列中。通过逗号分隔的列表或空格:
post_id => 1, post_title => 查理·卓别林... tag_name => 亚克力、粉笔、海报
但到目前为止,我唯一能得到的就是这样的多重结果:
post_id => 1, post_title => 查理卓别林... tag_name => 亚克力
post_id => 1, post_title => 查理卓别林... tag_name => 粉笔
post_id => 1, post_title => 查理卓别林... tag_name => 海报
有谁知道如何实现这一点...任何帮助将不胜感激,并提前感谢所有可以帮助我的人;-)
【问题讨论】:
标签: sql mysql aggregate-functions