title: Only SELECT rows where the date is less than a date from another table
body: <p>I'm refactoring some SQL to remove hardcoded dates that exist within several OR conditions, as part of an INSERT INTO statement.</p>
  <p>For example:</p>
  <pre><code>OR ( site = 'site.com' AND url = 'www.someurl.com' AND date &lt; '2021-01-01')
  </code></pre>
  <pre><code>OR ( site = 'site.com' AND url = 'www.otherurl.com' AND date &lt; '2019-09-09')
  </code></pre>
  <p>site = 'site.com' always stays the same.</p>
  <p>url = 'www.someurl.com' will have different URLs</p>
  <p>The dates will also change.</p>
  <p>In order to remove several lines that exist like the one above, I've created a reference table that contains a list of the site names, a boolean column to mark the interesting urls, and the dates (same as the hardcoded ones)</p>
  <p>I've sorted out everything except AND date &lt; '2021-01-01'. How do I select rows from Table A where the url matches the url from my reference table (Table B), where the date is less than the date in the reference table?</p>
  <p>I'm down a subquery rabbit hole with the following:</p>
  <pre><code>OR (site = 'site.com' AND url IN ( SELECT url_ref
                                         FROM REF_TABLE
                                         LEFT JOIN TABLE A
                                         ON url = url_ref) AND date &lt; ( SELECT start_date  
                                                                           FROM REF_TABLE
                                                                           LEFT JOIN TABLE A
                                                                           ON url = url_ref ) )
  </code></pre>
  <p>I was able to eliminate another large OR statement that contained a list of urls, but without dates. I'm stuck on these few cases where I need to only take rows where the date is less than a certain date, as defined in the reference table.</p>
  <p>That works like this:</p>
  <pre><code>            OR (ref.intersting = 't' AND url NOT IN ( SELECT url_ref
                                                           FROM REF_TABLE
                                                           WHERE url_ref IS NOT NULL ) )
  </code></pre>
  <p>Thank you!</p>
  <p>p.s. The purpose f this is so that I can stop editing a python script every time a new exception is created. Instead, I will just add a row to the reference table and the script won't need to change.</p>