开发者

mysql GROUP_CONCAT(query)

开发者 https://www.devze.com 2023-02-11 18:17 出处:网络
I\'m trying to run a query that looks like: SELECT GROUP_CONCAT(vehicles.id) FROM vehicles WHERE cars.id = vehicles.id

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

精彩评论

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