title: Query to check date range between start and end dates if already exists in database in postgres
body: <p>I have to allot ticket booking between two date range, ie., from an available start date and end end(which is not allotted previously). 
  For this, I need to check in database if there is already any allotment happened in between these dates</p>
  
  <p>For example, I need to allot ticket booking from 2017/04/20 to 2017/04/25 .Before inserting this record, I need to check if there is any booking previously happened between the start date 2017/04/20 and end date 2017/04/25 </p>
  
  <p>I have tried with below query.But it is not giving the correct result</p>
  
  <pre><code>select "id" 
  from "table" 
  where "from_date" &gt;= '2017-04-20' 
    and "to_date" &gt; '2017-04-20' 
    and "from_date" &lt; '2017-04-25' 
    and "to_date" &lt;= '2017-04-25'
  </code></pre>