I am trying to write a SQL Query that uses an ID to select a bunch of related rows. However, rather than a single row for each of the associated items I would like to concatenate them into a single row.
For example rather than:
ID Item
1 a
2 b
1 c
I would like:
ID Item 1 Item 2 ...
1 a c
2 b
Currently I am using a simple query but can't figure out how to do this:
Select
Investigation.ID,
Record.Item
FROM
Investigation
INNER JOIN
Record
ON Investigation.ID = Record.Inv_Id
This query is all part of a much larger one that involves multiple joins and a union. Eventually this will all be converted to XML in a format that hopefully resembles something like this:
<investigation>
<id>1</id>
<name>something</name>
<items>
<item>a</item>
<item>c</item>
</items>
<investigation>
<investigation>
<id>2</id>
<name>something else</name>
<items>
<item>b</item>
</items>
</investigation>