mysql GROUP_CONCAT(query)
I'm trying to run a query that looks like:
SELECT
GROUP_CONCAT(vehicles.id)
FROM
vehicles
WHERE
cars.id = vehicles.id
brings the right data:
1,2,3
However, now I want the brand name using GROUP_CONCAT
SELECT
GROUP_CONCAT(SELECT brand_name FROM brands WHERE vehicles.id = brand.id)
FROM
vehicles
WHERE
vehicles.id = 100
so I can get 'Bran开发者_如何转开发d1', 'Brand2', 'Brand3'
try
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
精彩评论