如何获取查询的所有标签?

时间:2013-10-08 05:24:48

标签: mysql

我正在使用标记系统中接受的答案here中所述的“Toxi”解决方案。我想搜索带有“Apple”标签的任何问题。我还需要返回该问题的所有其他标签,但我的查询只返回'Apple'标签:

SELECT b.id, allTags.* , GROUP_CONCAT( t.name order by t.name SEPARATOR ',') AS allTags
FROM tagmap bt, bookmark b, tag t
WHERE bt.tag_id = t.tag_id
AND (t.name = 'Apple')
AND b.id = bt.bookmark_id
GROUP BY b.id

给了我:

...,'...','...','...','2013-10-07','Apple' # only the matching tag...I need all the others

如何获得以下内容?:

...,'...','...','...','2013-10-07','Apple,Tim Cook,iPhone,iPad' # the rest of the tags for this question

2 个答案:

答案 0 :(得分:0)

添加此条件

AND (  t.name  NOT LIKE '%Apple%' )

答案 1 :(得分:0)

使用它:

SELECT b.id,
       alltags.*,
       (SELECT GROUP_CONCAT(t1.name ORDER BY t1.name SEPARATOR ',')
        FROM   tag t1) AS allTags
FROM   tagmap bt,
       bookmark b,
       tag t
WHERE  bt.tag_id = t.tag_id
       AND ( t.name = 'Apple' )
       AND b.id = bt.bookmark_id
GROUP  BY b.id