title: How to compare each row from table with all rows?
body: <p>Im using mysql.</p>
  
  <p>Compare each row with all left rows from this table and select the ID and timestamp where HEADING is between -15 &lt; Heading (from last row) &lt; +15 AND -10 &lt; timestamp (from last row) &lt; +10.</p>
  
  <pre><code>myTable
  id
  heading (In degrees)
  timestamp (in seconds)
  </code></pre>
  
  <p>Eg. of the 1st table rows:</p>
  
  <pre><code>1 - 50 - 133324565
  2 - 12 - 133324565
  3 - 10 - 133324565
  5 - 220 - 133324565
  6 - 35 - 133324565
  10 - 10 - 133324565
  11 - 15 - 133324565
  12 - 22 - 133324565
  16 - 168 - 133324565
  </code></pre>
  
  <p>As you see, ID's are not sequential, so I can't do this right?</p>
  
  <pre><code>SELECT T1.id,T1.heading,T2.id,T2.heading
  FROM mytable as T1, mytable as T2
  WHERE T1.id &gt; T2.id -1
  AND (T1.timestamp &gt; T2.timestamp -10 OR T1.timestamp &lt; T2.timestamp +10)
  AND (T1.heading &gt; T2.heading -15 OR T1.heading &lt; T2.heading +15)
  </code></pre>