0

Goal:

Query all emails sent for particular emails with the contact information and bounce information for each.

Issue:

Query results contain duplicate records.

Question:

How can I modify the query so that the resulting table doesn't have duplicates:

Query:

SELECT TOP 1000000000
    c.Id
    , s.SubscriberID
    , s.SubscriberKey
    , j.EmailName
    , CONCAT(c.Language__c, '-', c.Country__c) AS Locale
    , s.EventDate AS SendDate ,
    CASE 
        WHEN b.BounceType IS NOT NULL THEN 'Bounce'
        ELSE 'Success'
    END AS SendStatus
    , b.BounceType
    , b.SMTPBounceReason AS FailedReason
FROM 
    _Sent s
JOIN 
    _Job j ON s.JobID = j.JobID
LEFT JOIN 
    _Bounce b 
    ON s.JobID = b.JobID 
    AND s.ListID = b.ListID 
    AND s.BatchID = b.BatchID 
    AND s.SubscriberID = b.SubscriberID
LEFT JOIN 
    [Contact_Salesforce] c
    ON s.SubscriberKey = c.Email
WHERE
    (j.EmailName LIKE '%2FA_link_code%'
    OR j.EmailName LIKE '%2FA_deactivated%'
    OR j.EmailName LIKE '%2FA_activated%')
ORDER BY 
    s.EventDate
    , j.EmailName
    , s.SubscriberKey
    , b.BounceType
    , b.SMTPBounceReason 
    , c.Id
    , s.SubscriberID

1 Answer 1

0

De-dup the query using ROW_NUMBER() OVER (PARTITION BY s.SubscriberKey ORDER BY s.EventDate desc) as rn

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .