I have a table called CARS(id,brand,owner)
. Lets assume that owner is the foreign key here and my data in the table is:
1 mercedes Jack
2 mercedes John
3 bmw Jack
4 bmw John
6 audi Jack
What I want is to see an output like that:
1 mercedes, bmw, audi Jack
2 mercedes, bmw John
How can I manage this? I wrote this query below, but it is not working right. Any help would be appreciated.
select CARS.id, CARS.brand, CARS.owner
from CARS
inner join (Select c1.id, (c1.brand + ',' + c2.brand) from CARS c inner join CARS c2
on (c1.owner = c2.owner) where c1.brand <> c2.brand) as tempCars
on (CARS.id = tempCars.id)
I couldnt manage the merge process correctly..
Edit: My post looks like similar to the post Tab Alleman mentioned. I saw it before asking this question, but the answer is not that clear for me so I still couldnt figure out how to modify my query to serve my objective. Any additional help would be appreciated.