title: Query listing customers who ordered between dates and not ordered between dates
body: <p>I have two tables <code>customers</code> which has many <code>orders</code>.</p>
  <p>I would like to list customers who ordered between dates but not order (after) between later dates. I would like to figure out which customers didn't not return.</p>
  <p>I can write write query where I can list customers which ordered between dates.</p>
  <pre><code>SELECT
      &quot;customers&quot;.* 
  FROM
      &quot;customers&quot;
      LEFT JOIN orders ON orders.customer_id = customers.ID 
      AND orders.deleted_at IS NULL 
      AND ( orders.created_at BETWEEN '2020/06/05' AND '2020/06/13' ) 
  WHERE
      ( orders.customer_id IS NOT NULL ) 
  GROUP BY
      customers.ID
  </code></pre>
  <p>I can write also query which will give me a list who did not order between dates</p>
  <pre><code>SELECT
      &quot;customers&quot;.* 
  FROM
      &quot;customers&quot;
      LEFT JOIN orders ON orders.customer_id = customers.ID 
      AND orders.deleted_at IS NULL 
      AND ( orders.created_at BETWEEN '2020/06/16' AND '2020/06/18' ) 
  WHERE
      ( orders.customer_id IS NULL ) 
  GROUP BY
      customers.ID 
  </code></pre>
  <p>but cannot figure out how to have this list in one query.</p>
  <p>My last query (which don't work)</p>
  <pre><code>SELECT  
  &quot;customers&quot;.*
  FROM &quot;customers&quot; 
  
  LEFT JOIN &quot;orders&quot; ON &quot;orders&quot;.&quot;customer_id&quot; = &quot;customers&quot;.&quot;id&quot; AND &quot;orders&quot;.&quot;deleted_at&quot; IS NULL 
  
  WHERE 
  
  -- LAST WEEK
  AND (orders.created_at BETWEEN '2020/06/05' AND '2020/06/13' AND orders.customer_id IS NOT NULL) 
  -- NOT ORDERED TODAY 
  AND (orders.created_at BETWEEN '2020/06/16' AND '2020/06/18' AND orders.customer_id IS NULL)
  
  GROUP BY customers.id
  </code></pre>