查询两张关联表信息,原sql:

SELECT * FROM  car_life_info c

left JOIN shop_label sl

ON  c.shop_id = sl.shop_id 

 

出现重复 店铺名称

 

 合并 后面列label

新sql:

SELECT c.*,group_concat(sl.label_id) label_ids ,group_concat(l.label_name ) label_names
FROM car_life_info c
LEFT JOIN shop_label sl
ON c.shop_id = sl.shop_id
LEFT JOIN label l
ON sl.label_id = l.label_id
group by shop_id

 

问题解决!

 

版权声明:本文为vectorear原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/vectorear/p/8931953.html