I am creating a view from multiple tables. Each table being included has a column named Contact_ID. I am using MS SQL 2005. I see that I can use DISTINCT to return a unique set
Initially misread the question, you will need to group all the data but if you want to show all the data and there are uniques, you need to use min or max in some cases, if someone has 2 phones...what do you want to show?
WITH q AS
(
SELECT *,
ROW_NUMBER() OVER (PARTITION BY dbo.[1_MAIN - Contacts].Contact_ID ORDER BY dbo.[1_MAIN - Contacts].Contact_ID) AS rn
FROM dbo.[1_MAIN - Contacts]
INNER JOIN
dbo.Referral
ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.Referral.Referral_ID
INNER JOIN
dbo.prov_training_records
ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.prov_training_records.Contact_ID
LEFT OUTER JOIN
dbo.Resource_Center
ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.Resource_Center.Contact_ID
FULL OUTER JOIN
dbo.Providers
ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.Providers.Contact_ID
)
SELECT *
FROM q
WHERE rn = 1