Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设 id_post 3 有 4 个链接标签 1、2、3、4(足球、篮球、网球和高尔夫)。
有没有办法在一行中返回这样的东西?
谢谢
采用:
SELECT p.id_post GROUP_CONCAT(DISTINCT t.name SEPARATOR ' ') FROM POST p JOIN POST_TAG pt ON pt.id_post = p.id_post JOIN TAG t ON t.id_tag = pt.id_post_tag GROUP BY p.id_post
请注意,默认分隔符是逗号,因此如果您不想在标签名称之间定义一个空格,则必须定义一个空格。
文档: