Skip to main content
1 of 3
0xsegfault
  • 6.6k
  • 2
  • 32
  • 69

Using a UNION should get you the results you want an not duplicate.

SELECT l.[EmailAddress], e.[First_name]
FROM _Job j with (nolock)
INNER JOIN _Sent s with (nolock)
ON j.JobID = s.JobID
INNER JOIN _ListSubscribers l with (nolock)
ON l.subscriberID = s.subscriberID
INNER JOIN _EnterpriseAttribute e with (nolock)
ON l.subscriberID = e._subscriberID
WHERE s.EventDate < GetDate()
AND e.Segment = 'Customer'
AND j.EmailName NOT LIKE 'newsletter_%'
AND l.ListID = 919445

UNION

SELECT l.[EmailAddress], e.[First_name]
FROM _ListSubscribers l with (nolock)
INNER JOIN _EnterpriseAttribute e with (nolock)
ON l.subscriberID = e._subscriberID
WHERE NOT EXISTS (SELECT * FROM _Sent WHERE _Sent.[subscriberID] = l.[subscriberID])
AND e.Segment = 'Customer'
AND l.ListID = 919445

Warning:

Depending on the size of your list this might time out. Unions take alot longer

0xsegfault
  • 6.6k
  • 2
  • 32
  • 69