title: MySQL: IN clause for dates BETWEEN a start and end date?
body: <p>I have list of dates in the format <code>YYYY-MM</code>, and I have a table full of records with a <code>starts_at</code> and <code>ends_at</code> column.</p>
  
  <p>I want to find all records for which any given date in the passed-in list is within the <code>starts_at</code> and <code>ends_at</code> range.</p>
  
  <p>So, given <code>2011-01, 2011-05, 2011-10</code>, I want:</p>
  
  <pre><code>| id | starts_at           | ends_at             | title                             |
  | 3  | 2010-12-05 00:00:00 | 2011-02-02 00:00:00 | something cool                    |
  | 4  | 2011-03-14 00:00:00 | 2011-05-01 00:00:00 | something else really cool        |
  | 5  | 2011-10-31 00:00:00 | 2012-12-23 00:00:00 | argh! end of the world! not cool! |
  </code></pre>
  
  <p>... while these records would be omitted:</p>
  
  <pre><code>| id | starts_at           | ends_at             | title                             |
  | 6  | 2010-10-05 00:00:00 | 2010-12-02 00:00:00 | something uncool                  |
  | 7  | 2011-03-14 00:00:00 | 2011-04-31 00:00:00 | something else really uncool      |
  | 8  | 2011-12-23 00:00:00 | 2013-01-01 00:00:00 | yay! we're still alive! cool!     |
  </code></pre>
  
  <p>How would I write this <code>WHERE</code> condition in SQL?</p>
  
  <hr>
  
  <p><strong>Clarification</strong>: I'm looking for a solution in pure SQL (I'm working with a stored procedure, so dynamic injection through some other language like PHP isn't really possible, so far as I know), and the list of dates is being passed in to the query as a <code>string</code> (HTML form input). I would love to break it down into sequential <code>BETWEEN</code> statements if I could do that programmatically in SQL, but I've no clue how to do that.</p>
  
  <p>Basically, I need a way to express the following logic in pure SQL:</p>
  
  <pre><code>$months = explode(',', '2011-01,2011-05,2011-10');
  $q = "SELECT records.* FROM records WHERE";
  foreach($months as $month) {
    $q .= " '$month' BETWEEN records.starts_at AND records.ends_at OR";
  }
  $q = substr($q, 0, -3) . ';';
  </code></pre>