select distinct one column with all instances of another column in a second column
You can use a pattern like this:

SELECT files.database_id, db.name AS DatabaseName,
        STUFF((SELECT ', ' + names.name
                FROM sys.master_files names
                WHERE names.database_id = files.database_id
                FOR XML PATH(''),TYPE).value('.','VARCHAR(MAX)')
            , 1, 2, '') AS NameList
FROM sys.master_files files
JOIN sys.databases db
    ON files.database_id = db.database_id
GROUP BY files.database_id, db.name