<p>I have two tables, both with start time and end time fields. I need to find, for each row in the first table, all of the rows in the second table where the time intervals intersect.</p>

<p>For example:</p>

<pre><code>           &lt;-----row 1 interval-------&gt;
&lt;---find this--&gt; &lt;--and this--&gt; &lt;--and this--&gt;
</code></pre>

<p>Please phrase your answer in the form of a SQL <code>WHERE</code>-clause, AND consider the case where the end time in the second table may be <code>NULL</code>.</p>

<p>Target platform is SQL Server 2005, but solutions from other platforms may be of interest also.</p>

```
```
SELECT * 
FROM table1,table2 
WHERE table2.start <= table1.end 
AND (table2.end IS NULL OR table2.end >= table1.start)
```
```