开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜