title: Best SQL query to select events between two dates
body: <p>After read a lot of posts about this. I need a good way to select events between two dates. The possible conditions are shown in the following figure:</p>
  
  <p><a href="https://i.stack.imgur.com/RTfmf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RTfmf.jpg" alt="Date range for events"></a></p>
  
  <p>My first attempt is the following:</p>
  
  <pre><code>SELECT *
  FROM events
  WHERE 
  (
   start_date BETWEEN $start_select AND  $end_select
   OR
   end_date BETWEEN $start_select AND $end_select
  )
  OR
  (
   start_date &lt;=  $start_select
   AND
   end_date &gt;= $end_select
  )
  </code></pre>
  
  <p>The problem is that it takes a long time to make the query.</p>
  
  <p>Then I saw this post: <a href="https://stackoverflow.com/questions/14208958/select-data-from-date-range-between-two-dates">Select data from date range between two dates</a> where @dmlukichev talks about exclude all wrong options:</p>
  
  <p>Something like this:</p>
  
  <pre><code>SELECT *
  FROM events
  WHERE NOT 
  (
   start_date &lt;  $start_select
   OR
   end_date &gt; $end_select
  )
  </code></pre>
  
  <p>But it does not work me.</p>
  
  <p>Any ideas?</p>