mysql 多表联合查询,单字段多条数据合并问题,求教,谢谢

A 表:
id mid title content
1 1 主题1 内容1
2 2 主题2 内容2

B 表:
id mid viewer
1 1 aaa
2 1 bbb
3 2 ccc
4 2 ddd

C 表:
id author
1 张三
2 李四

A、B、C表联合查询结果是这样:
id mid title viewer author
1 1 主题1 aaa,bbb 张三
2 2 主题2 ccc,ddd 李四

3个回答

select x.id,y.mid,y.title,GROUP_CONCAT(z.viewer) viewer,x.author from c x LEFT JOIN a y on x.id = y.mid LEFT JOIN b z on x.id = z.mid group by x.id

hjacto
hjacto 非常感谢 很有参考性,已经解决
大约 4 年之前 回复
hjacto
hjacto SELECT a.id ,a.title,c.author,GROUP_CONCAT(b.viewer SEPARATOR ',') as viewer FROM A as a LEFT JOIN B as b ON a.id = b.mid LEFT JOIN ''C as c ON a.mid = c.id 你好帮我看下为何会这样,只查出来一笔数据?
大约 4 年之前 回复

SELECT a.id ,a.title,c.author,GROUP_CONCAT(b.viewer SEPARATOR ',') as viewer FROM A as a LEFT JOIN B as b ON a.id = b.mid LEFT JOIN ''C
as c ON a.mid = c.id

按照这么写结果居然只有一条,搞不懂啊,且结果都不对
id mid title viewer author
1 1 主题1 aaa,bbb ,ccc,ddd 张三

W904256426
W904256426 SELECT a.id ,a.title,c.author,GROUP_CONCAT(b.viewer SEPARATOR ',') as viewer FROM A as a LEFT JOIN B as b ON a.mid= b.mid LEFT JOIN ''C as c ON a.mid = c.id
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问