内容简介:翻译自:https://stackoverflow.com/questions/8144848/how-to-find-all-the-tags-of-each-page-and-then-concat-the-tags-into-one-column
如何找到每个页面的所有标签,然后将标签连成一列?
举个例子,
页表,
page_id 1 2 3 4
标签表,
tag_id tag_name 1 A 2 B 3 C 4 D
标记表,
page_id tag_id 1 1 1 2 1 3 3 2 3 3
我的工作查询,
SELECT
p.page_id,
GROUP_CONCAT(t.tag_name ORDER BY t.tag_name ASC SEPARATOR ",") AS tags
FROM root_pages AS p
LEFT JOIN root_mm_pages_tags AS m
ON p.page_id = m.page_id
LEFT JOIN root_tags AS t
ON t.tag_id = m.tag_id
WHERE p.page_id = t.page_id
这是我追求的结果,
page_id tags 1 A, B, C 2 NULL 3 B, C 4 NULL
尝试不使用ON p.page_id = tt.page_id和WHERE p.page_id = t.page_id;也使最后一次加入成为常规性能.
SELECT
p.page_id,
GROUP_CONCAT(t.tag_name ORDER BY t.tag_name ASC SEPARATOR ",") AS tags
FROM root_pages AS p
LEFT JOIN root_mm_pages_tags AS m
ON p.page_id = m.page_id
JOIN root_tags AS t
ON t.tag_id = m.tag_id
GROUP BY p.page_id
翻译自:https://stackoverflow.com/questions/8144848/how-to-find-all-the-tags-of-each-page-and-then-concat-the-tags-into-one-column
以上所述就是小编给大家介绍的《php – 如何找到每个页面的所有标签,然后将标签连成一列?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Art of Computer Programming, Volume 4, Fascicle 3
Donald E. Knuth / Addison-Wesley Professional / 2005-08-05 / USD 19.99
Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 4, Fascicle 3》 这本书的介绍吧!
随机密码生成器
多种字符组合密码
RGB HSV 转换
RGB HSV 互转工具