title: Query timing out / making query more efficient (exacttarget)
body: <p>Here is my query, can anyone see any way to make this more efficient so it doesn't time out?  I'm using Exacttarget (Salesforce Marketing Cloud).  It has a 30 minute timeout limit.  I've tried moving things around but it always seems to error.  I'm kind of a beginner with SQL but I've been hitting it fairly hard the last week.  My query is below.  THanks!</p>
  
  <pre><code>SELECT DISTINCT c.Email,  c.FName
  FROM ENT.Contacts c WITH(NOLOCK)
  INNER JOIN ENT.RegistrationData r WITH(NOLOCK)
  ON c.Email  =  r.RegistrationContactEmail
  LEFT Join ENT._Subscribers s  WITH(NOLOCK)
  ON c.Email =  s.SubscriberKey
  AND s.status NOT IN ('unsubscribed','held')
  
  WHERE
  
  (
      (
          (
              (
                  r.RegistrationEmailOptStatus  =  '1' AND
                  r.RegistrationEventType  =  'Wedding' AND
                  r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
                  r.RegistrationCountry IN ('USA') AND
                  r.RegistrationEventDate &lt; '2014-05-31'
              )
  
              OR
  
              (
                  r.RegistrationEmailOptStatus  =  '1' AND
                  r.RegistrationEventType  =  'Prom' AND
                  r.RegistrationEventRole ='Prom' AND
                  r.RegistrationCountry IN ('USA') AND
                  r.RegistrationEventDate BETWEEN '2014-01-01' AND '2015-12-31'
              )
          )
  
          AND
  
          (
              (
                  c.Email IN
                  (
                      SELECT DISTINCT 
                          s.SubscriberKey AS Email
                      FROM 
                          _Open s
                      WHERE
                          datediff(mm,s.EventDate, getdate()) &lt;= 3
                  )
              )
              OR
              (
                  c.Email IN
                  (
                      SELECT DISTINCT 
                          s.SubscriberKey AS Email
                      FROM 
                          _Click s
                      WHERE
                          datediff(mm,s.EventDate, getdate()) &lt;= 3
                  )
              )
          )
  
      )
  
      OR
  
      (
          r.RegistrationEmailOptStatus  =  '1' AND
          r.RegistrationEventType  =  'Wedding' AND
          r.RegistrationEventRole IN ('Bride','Other','Bridesmaid','Mother Of the Bride') AND
          r.RegistrationCountry IN ('USA') AND
          r.RegistrationEventDate BETWEEN '2015-05-01' AND '2015-05-31'
      )
  )
  </code></pre>