title: Check overlap of date ranges in MySQL
body: <p>This table is used to store sessions (events):</p>
  
  <pre><code>CREATE TABLE session (
    id int(11) NOT NULL AUTO_INCREMENT
  , start_date date
  , end_date date
  );
  
  INSERT INTO session
    (start_date, end_date)
  VALUES
    ("2010-01-01", "2010-01-10")
  , ("2010-01-20", "2010-01-30")
  , ("2010-02-01", "2010-02-15")
  ;
  </code></pre>
  
  <p>We don't want to have conflict between ranges.<br>
  Let's say we need to insert a new session from <strong>2010-01-05</strong> to <strong>2010-01-25</strong>.<br>
  We would like to know the conflicting session(s).</p>
  
  <p>Here is my query:</p>
  
  <pre><code>SELECT *
  FROM session
  WHERE "2010-01-05" BETWEEN start_date AND end_date
     OR "2010-01-25" BETWEEN start_date AND end_date
     OR "2010-01-05" &gt;= start_date AND "2010-01-25" &lt;= end_date
  ;
  </code></pre>
  
  <p>Here is the result:</p>
  
  <pre><code>+----+------------+------------+
  | id | start_date | end_date   |
  +----+------------+------------+
  |  1 | 2010-01-01 | 2010-01-10 |
  |  2 | 2010-01-20 | 2010-01-30 |
  +----+------------+------------+
  </code></pre>
  
  <p>Is there a better way to get that?</p>
  
  <hr>
  
  <p><a href="http://sqlfiddle.com/#!9/f21cc/2" rel="noreferrer">fiddle</a></p>