I have tables like
-- REGIONS
-- ==========================
-- id | name
-- ==========================
-- 1 | 'Western Europe'
-- 2 | 'United States'
-- 3 | 'United Kingdom'
-- 4 | 'Middle East and Africa'
-- 5 | 'Latin America'
-- 6 | 'Japan'
-- 7 | 'India'
-- 8 | 'Germany'
-- 9 | 'Greater China'
-- 10 | 'France'
-- 11 | 'Central and Eastern Europe'
-- 12 | 'Canada'
-- 13 | 'Asia Pacific'
and
-- Partners
-- ==============================================================================================================
-- id | first_name | last_name | org_name | email | region_id
-- ==============================================================================================================
-- 1 | 'Dick' | 'Cheney' | 'Haliburton' | 'DCheney@Haliburton.org' | 2
-- 2 | 'Warren' | 'Buffet' | 'Berkshire Hathaway' | 'WarrenBridgemaster@bershire.org' | 2
and a procedure that gets the partner's an their associated region names like
CREATE PROCEDURE GetPartnersWithRegion
AS
SELECT Partners.id,
Partners.first_name,
Partners.last_name,
Partners.org_name,
Partners.email,
Regions.name
FROM Partners INNER JOIN Regions
ON Partners.region_id=Regions.id
ORDER BY org_name ASC
Now, as an extra requirement of my development project, I have a table that makes a one-to-many relationship of partners with regions like
-- Destinations
-- ================================
-- id | partner_id | region_id
-- ================================
-- 1 | 1 | 1
-- 2 | 1 | 2
if Dick Cheney
is associated with the regions Western Europe
and United States
. What I'd like to do, if possible, is modify GetPartnersWithRegion
so that it has these destinations separated by a comma, like
-- Results
-- =====================================================================================================================================================
-- id | first_name | last_name | org_name | email | region_name | destinations
-- =====================================================================================================================================================
-- 1 | 'Dick' | 'Cheney' | 'Haliburton' | 'DCheney@Haliburton.org' | 'United States' | 'Western Europe, United States'
-- 2 | 'Warren' | 'Buffet' | 'Berkshire Hathaway' | 'WarrenBridgemaster@bershire.org' | 'United States' | 'Latin America, 'Asia Pacific'
Is this possible? Or is there a different way I should be doing this in the first place?