title: SQL between subquery
body: <p>I would like to know how to run a SQL query that returns events that have a time that is in a valid segment.</p>
  
  <p>For example, I have the two tables,</p>
  
  <p><strong>Event</strong></p>
  
  <pre><code>event_id event_time
  0        134
  1        434
  2        4300
  </code></pre>
  
  <p><strong>Segment</strong></p>
  
  <pre><code>segment_type segment_start_time segment_end_time
  data1         100                130
  data1         200                500
  data1         700                8000
  veto1         400                440
  data2         150                450
  data2         4000               5000
  veto2         175                200
  </code></pre>
  
  <p>I want a query that would return</p>
  
  <pre><code>event_id event_time
  1        434
  2        4300
  </code></pre>
  
  <p>I was thinking something like</p>
  
  <pre><code>SELECT * 
  FROM event
  WHERE 
      event.event_time &gt; (SELECT segment.segment_start_time FROM segment)
      AND 
      event.event_time &lt; (SELECT segment.segment_end_time FROM segment)
  </code></pre>
  
  <p>But this just returns nothing. What am I doing wrong?</p>
  
  <p>The next step I want to do is to find events times that are;</p>
  
  <p>between a 'data' segment start time and end time AND
  NOT between a 'veto' segment start time and end time</p>
  
  <p>And finally, I actually have two type of data segments and veto segments. I want to return events that have times;</p>
  
  <p>between a 'data1' segment start time and end time AND</p>
  
  <p>between a 'data2' segment start time and end time AND</p>
  
  <p>NOT between a 'veto1' segment start time and end time AND</p>
  
  <p>NOT between a 'veto2' segment start time and end time</p>
  
  <p>So from my example table above, the output I want would be</p>
  
  <pre><code>event_id event_time
  2        4300
  </code></pre>