2

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 'Brand1', 'Brand2', 'Brand3'

1
  • 1
    What is WHERE cars.id = vehicles.id? there is no cars in your query. Commented Feb 18, 2011 at 18:59

1 Answer 1

9

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.