Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Convert multiple rows in a table into one row based on the primary key

$
0
0

I have 2 tables

CREATE TABLE Files (FileID int, fileName varchar(20))
insert into Files values (1,'F1')
insert into Files values (2,'F2')
insert into Files values (3,'F3')
CREATE TABLE Versions (FileID int, VersionNum varchar(10))
insert into Versions values (1, 'V1')
insert into Versions values (1, 'V2')
insert into Versions values (1, 'V3')
insert into Versions values (2, 'V1')

The two tables join using FileID.  I want a listing of the fileName and the all corresponding versions on one line.  There may not be a version for a file or there may be multiple versions for the file.  The output I want is

F1, V1, v2, v3
F2, V1
F3

Any help would be appreciated.


lg


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>