I have two tables as follows
Group
Id, Name, ParentId
1, North, NULL
2, South, NULL
3, London, 2
4, Brighton, 2
5, Fulham, 3
6, SuperStores, NULL
StoreAndGroup
Id, StoreId, GroupId
1, 41, 2
2, 52, 3
3, 88, 5
4, 88, 6
5, 41, 6
etc
I want to produce a table that shows all stores that belong to each group (including subgroups), so the above would become
GroupId, StoreId
2, 41
2, 52
2, 88
3, 52
3, 88
5, 88
6, 88
6, 41
I can use a recursive cte to show me all children of a particular group but am a bit stuck as to how to incorporate the additional data.
Actually it turned out to be a simple join
Darren