我正在尝试运行看起来像这样的查询:
SELECT
GROUP_CONCAT(vehicles.id)
FROM
vehicles
WHERE
cars.id = vehicles.id
带来正确的数据:
1,2,3
但是,现在我想要使用GROUP_CONCAT
的品牌名称SELECT
GROUP_CONCAT(SELECT brand_name FROM brands WHERE vehicles.id = brand.id)
FROM
vehicles
WHERE
vehicles.id = 100
所以我可以'Brand1', 'Brand2', 'Brand3'
答案 0 :(得分:9)
试
SELECT
GROUP_CONCAT(brands.brand_name)
FROM
vehicles
inner join brands on vehicles.id=brands.id
inner join cars on cars.id=vehicles.id
WHERE
cars.id = vehicles.id