I have this SQL query and I cannot perform it due to violation of primary key.
The primary of the source data extensions are the following :
- Account : Email
- Opportunity : OpportunityId
- Info_Magasin_AllSites : code_mag
The primary key of the target data extension is the Email
Can someone help me
Thanks a lot
Anne-Sophie
SELECT DISTINCT
account.FirstName as FirstName,
account.LastName as LastName,
account.AccountID as AccountID,
account.Email as Email,
account.Mobile as Mobile,
account.Subscriber_Key as Subscriber_Key,
account.MobileCountryCode as MobileCountryCode,
Opportunity.Etape as Etape,
Opportunity.OpportunityId as OpportunityId,
Opportunity._CustomObjectKey as ObjectKey,
Opportunity.Code_Magasin__c as code_mag,
Opportunity.MethodePaiement as MethodePaiement,
MAX(Opportunity.CreatedDate) as CreatedDate,
Opportunity.RaisonPerte as RaisonPerte,
Opportunity.CloseDate as CloseDate,
opportunity.Amount as Amount,
Opportunity.Produits as Produits,
Info_Magasin_AllSites.nom_mag as Magasin,
Info_Magasin_AllSites.adr_mag as adr_mag,
Info_Magasin_AllSites.nom_resp_magasin as nom_resp_magasin,
Info_Magasin_AllSites.tel_magasin as tel_magasin,
Info_Magasin_AllSites.email_magasin as email_magasin,
Info_Magasin_AllSites.Demande_avis_Google as Demande_avis_Google,
Info_Magasin_AllSites.code_Postal as code_Postal,
Info_Magasin_AllSites.Lien_Google as Lien_Google,
Info_Magasin_AllSites.Adresse_Google as Adresse_Google
FROM AllAccount_DedupEmail_Last account
INNER JOIN SelectOnly_AllOpportunity Opportunity
ON account.AccountID = Opportunity.AccountId
INNER JOIN Info_Magasin_AllSites
ON Opportunity.Code_Magasin__c = Info_Magasin_AllSites.code_mag
WHERE Opportunity.Etape != 'Annulée' and Opportunity.Etape != 'Closed won'
group by account.FirstName, account.LastName, account.AccountID, account.Email, account.Mobile, account.Subscriber_Key , account.MobileCountryCode, Opportunity.Etape, Opportunity.Code_Magasin__c, Opportunity.OpportunityId, Opportunity._CustomObjectKey , Opportunity.MethodePaiement, Opportunity.RaisonPerte, Opportunity.CloseDate, opportunity.Amount, Opportunity.Produits, Info_Magasin_AllSites.nom_mag, Info_Magasin_AllSites.adr_mag, Info_Magasin_AllSites.nom_resp_magasin, Info_Magasin_AllSites.tel_magasin, Info_Magasin_AllSites.email_magasin, Info_Magasin_AllSites.Demande_avis_Google, Info_Magasin_AllSites.code_Postal, Info_Magasin_AllSites.Lien_Google, Info_Magasin_AllSites.Adresse_Google
group by Account.Email
, this would cause problems if you have different values or multiple values for the same column per email though => Research Adams posts and try to write a subselect statement ;)