Can JOIN or UNION collapse multiple rows for use in a subquery
I would like to get all tags that match the specified id, where:
select tag where id = 101 //returns 4 rows
soup
nuts
juice
milk
Only now I would like to use this as a subquery -
select idList, (select tag where id = 101) itemsOnList, shopper from assignedLists
becomes:
10 | soup,nuts,juice,milk | Mom
+2
a source to share
3 answers
This is actually quite a difficult thing to believe or not. The best link I've seen for this is here . The following query was taken from the example in this article. There are more options.
select
idList,
(
select name + ','
from tag
where id = 101
for xml path('')
) as itemsOnList,
shopper
from
assignedLists
+1
a source to share