This is linked to my previous Qn
Table A:
ID Rank Name
1 100 Name1
1 45 Name2
2 60 Name3
2 42 Name4
2 88 Name5
3 50 name6
3 50 name7
Table B:
ID FileName
1 fn1
2 fn2
3 fn3
What I want is
1 fn1 name1
2 fn2 name5
3 fn3 name6,name7
Here is my code that doesnt deal with the duplciate ranks above, so I get two rows for value 3.
select B.*,A.Name
LEFT JOIN ( SELECT A.Id, MAX(A.Rank)as Rank
FROM A
GROUP BY A.Id
) AS NewA
JOIN A
on A.Rank = NewA.Rank
AND A.ID = NewA.Id
on NewA.ID = B.ID
How do I modify this to give me A.name seperated by comma when the ranks are same for a Id?
Thanks
You will need to use a CTE to flatten this out.
This should plug directly into SQL and work with the data given as an example. Obviously, you will need to update the queries for your real data since this is probably not your real schema