title: how to find overlapping record with between date
body: <p>I am using MySQL, I have following table structure</p>
  
  <pre><code>Id  id2 classId sectionId   validFrom   validTill
  ------------------------------------------------------
  1   1       5       13      2016-01-01  2016-03-30
  2   1       5       22      2016-01-15  2016-03-30
  3   1       5       23      2016-01-15  2016-04-29
  4   1       5       13      2016-04-01  2016-04-30
  9   10      6       24      2016-01-17  2016-02-05
  10  10      6       25      2016-01-23  2016-02-05
  11  10      6       24      2016-01-31  2016-02-05
  </code></pre>
  
  <p>My SQL statement is</p>
  
  <pre><code>SELECT count(*) as timeCount FROM TimeTableClassSection a 
  WHERE classId=5 AND sectionId=13 AND ((a.ValidFrom BETWEEN '2016-01-18' AND '2016-01-24') OR (a.ValidTill BETWEEN '2016-01-18' AND '2016-01-24'))
  </code></pre>
  
  <p>Its returning <code>timeCount = 0</code>. But it should return 1 as record with Id=1 falls between this date range <code>('2016-01-18' AND '2016-01-24')</code></p>
  
  <p>I am trying to achieve, find out any overlapping record for particular classId &amp; sectionId between provided date range. 
  If <code>classId=5</code> and <code>sectionId=13</code> has <code>validFrom=2016-01-01</code> <code>validTill=2016-03-30</code> exist, then any date range between this date range <code>('2016-01-18' AND '2016-01-24')</code> should throw this record as count. </p>
  
  <pre><code>If I give date range 2015-12-25 to 2016-09-20 then record count should = 1
  If I give date range 2016-2-1 to 2016-02-20 then record count should = 1
  If I give date range 2016-2-1 to 2016-09-20 then record count should = 1
  </code></pre>
  
  <p>What wrong I am doing here ... all date format is in YYYY-MM-DD</p>