0

我正在使用此处接受的答案中描述的“毒物”解决方案用于标记系统。我想搜索带有“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
4

2 回答 2

0

添加这个条件

AND (  t.name  NOT LIKE '%Apple%' )
于 2013-10-08T06:45:57.607 回答
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 
于 2013-10-08T06:48:45.967 回答