SQL查询一对多返回一条数据

一。查询中product和product_img是一对多的关系(数据库是MySQL)
select p.id,
       p.product_cost_price,
       p.product_trade_price,
       p.product_sale_price,
       p.collect_num,
       p2.collect_status,
       p2.ID as collect_id,
       p3.name,
       GROUP_CONCAT(p1.img_path SEPARATOR '|') as imgPath
from dn_product as p
       left join dn_product_img as p1 on p.id = p1.product_id
       left join dn_product_collect as p2 on p.id = p2.product_id
       left join dn_person as p3 on p3.ID = p2.person_id
group by p.ID
limit 10

SQL查询一对多返回一条数据_第1张图片

二。mysql 给查询的数据加前(后)缀

select 
       CONCAT("../Product/",img_path)  as date
from dn_product_img as p

你可能感兴趣的:(数据库)