As Jobas Lambery has started, the error is happening as the same primary key is attempted to be added twice.
There are two ways to tix this:
- You can add another primary key to the target DE. This will mean that you are likely to have duplicate subscriberkey's in your resulting data (which may not be a good idea)
Or (Probably the better option)
- You can add a dedupe criteria to your SQL query. Assuming the Subscriberkey is your PK, please see the query below. We are finding all common subscriberkey's (PK) in your data, ordering them by [Registration Date] from most recent subscription to least recent and taking that most recent record.
I have also optimized your query by replacing the "NOT EXISTS" section with a LEFT JOIN. The system will processes this more efficiently than the "NOT EXISTS" section.
[Date Of Birth],
[Registration Date] as [Subscription Date]
t1.[Date Of Birth],
t1.[Registration Date] as [Subscription Date],
ROW_NUMBER() OVER (PARTITION BY t1.[Subscriberkey] ORDER BY t1.[Registration Date] ASC) AS [RN] /*dedupe at Subscriberkey lvl*/
FROM [Welcome Triggered Send] t1
LEFT JOIN [Master DE Newsletter] t2
ON t2.EmailAddress = t1.EmailAddress
SubscribedToNewsletter = 'TRUE'
t2.EmailAddress IS NULL
) AS SQ
[RN] = 1
Read this info to better understand the SQL criteria to dedupe:
I hope this helps