参考:
合并:
MySQL中group_concat函数
完整的语法如下:
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
三表联查:
例:
有三个表 a b c
c.aid对应a.aid
c.bid对应b.bid
select a.aname, b.bname, c.cname from c
inner join a on c.aid=a.aid inner join b on c.bid=b.bid
select a.anme, b.bname, c.value
from a,b,c
where a.aid = c.aid and b.bid = c.bid
实战:
select b.id,GROUP_CONCAT(a.m_name SEPARATOR' '),b.b_name from t_medicinal_info a, t_product_base b, t_medicinal_productbase c
where a.id=c.t_medicinal_id and b.id=c.t_product_base_id group by b.id