Postgres LEFT JOIN with WHERE condition
<p>I need to left join two tables with a where condition:</p>
<p>Table <code>time_table</code></p>
<pre class="lang-none prettyprint-override"><code>id     rid        start_date                end_date
1       2     2017-07-01 00:00:00     2018-11-01 00:00:00
2       5     2017-01-01 00:00:00     2017-06-01 00:00:00
3       2     2018-07-01 00:00:00     2020-11-01 00:00:00
</code></pre>
<p>Table <code>record_table</code></p>
<pre class="lang-none prettyprint-override"><code>id      name                 date
1      record1       2017-10-01 00:00:00
2      record2       2017-02-01 00:00:00
3      record3       2017-10-01 00:00:00
</code></pre>
<p>I need to get all those records which are present under given date range. In the above example, I need those records that lie under range for <code>rid = 2</code> only. Hence the output for the above query needs to be:</p>
<pre class="lang-none prettyprint-override"><code>1      record1       2017-10-01 00:00:00    
3      record3       2017-10-01 00:00:00
</code></pre>