Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>First, let's exhaustively examine what an "overlap" means and optimize your boolean expression.</li> </ul> <hr> <p>An overlap is any of the following conditions:</p> <pre> Start1 End1 --------------------------------------------------------------------------------- Start2 End2 Start2 End2 Start2 End2 </pre> <p>And is NOT any of the following conditions:</p> <pre> Start1 End1 --------------------------------------------------------------------------------- Start2 End2 Start2 End2 </pre> <p>If you look carefully, you'll notice <code>Start2 &lt; End1 AND End2 &gt; Start1</code> defines this relationship, so you can reduce your expression to this.</p> <hr> <ul> <li><p>Second, you can put this in a <code>WHERE</code> condition for your cursor instead of looping through every row and checking.</p></li> <li><p>Third, since you're just checking whether something exists or not, you can use an <code>IF EXISTS</code> clause instead of looping through a cursor and checking.</p></li> <li><p>Finally, you can condense this all down to a single query using an <code>INNER JOIN</code> on itself or <code>WHERE EXISTS</code>, depending on how you want your final output to look. To get all the overlaps in the table, you can try something like the following (the <code>t2.id &gt; t1.id</code> is to only get each overlap once):</p> <pre><code>SELECT t1.id, t2.id FROM MyTable t1 INNER JOIN MyTable t2 ON t2.id &gt; t1.id AND t2.start &lt; t1.end AND t2.end &gt; t1.start </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload