I have a SQL Server database. This database includes three tables:
Group
ID (int: primary key)
Name (string)
IsActive (bit)
Product
ID (int: primary key)
Name (string)
Description (string)
PublicID (int)
GroupProductLookup
ID (int: primary key)
PublicID (int)
GroupID (int)
I need a query that will return every group and the list of public IDs of the products that are in the group. If there are no products, null or an empty set will work. An example would be:
| GroupID | Name | Products |
|---------|-------|-----------|
| 1 | Alpha | (1, 5, 8) |
| 2 | Beta | (none) |
| 3 | Cat | (2, 7) |
I know how to query the groups. But, I don't know how to get a list of the product ids that belong in the group. This is what I have so far..
SELECT
g.ID as 'GroupID',
g.Name as 'Name',
FROM
[Group] g
How do I get the products IDs?
Thanks!