You can use CROSS APPLY
for this combined with XML PATH
functions as follows.
It looks a bit lengthy but it includes sample data matching your sample so you can test it before you apply it to your real tables.
DECLARE @trips TABLE([Name] varchar(50), [Capital Visited] varchar(50))
INSERT INTO @trips
VALUES
('Joe', 'London'),
('Fred', 'Tokyo'),
('Joe', 'Berlin'),
('Bob', 'Paris'),
('Fred', 'London'),
('Fred', 'Madrid'),
('Bob', 'Rome')
/* Uncomment below to check the table data looks as expected */
-- SELECT [Name] ,[Capital Visited] From @trips
SELECT DISTINCT
[Name], cx.Captials
FROM
@trips t
CROSS APPLY ( SELECT Stuff(
(
SELECT ', ' + [Capital Visited]
FROM @trips WHERE [Name] = t.[Name]
FOR XML PATH('')
), 1, 2, '') AS Captials
) cx
This gives you following results
Name Captials
Bob Paris, Rome
Fred Tokyo, London, Madrid
Joe London, Berlin
Rather than me explaining the answer in full, there is a reasonable explaination here.
How Stuff and 'For Xml Path' work in Sql Server