title: How to find couples (or tuples) in a Sqlite query?
body: <p>Let' say we have this dataset:</p>
  
  <pre><code>import sqlite3
  db = sqlite3.connect(':memory:')
  c = db.cursor()
  c.execute('CREATE TABLE mytable (id integer, description text)')
  c.execute('INSERT INTO mytable VALUES (2, "abc")')
  c.execute('INSERT INTO mytable VALUES (5, "def")')
  c.execute('INSERT INTO mytable VALUES (18, "geh")')
  c.execute('INSERT INTO mytable VALUES (19, "ijk")')
  c.execute('INSERT INTO mytable VALUES (27, "lmn")')
  </code></pre>
  
  <p><strong>How to find pairs / couples of rows for which their ID is distant of at most 3?</strong> i.e. it should return the rows (2,5) and (18, 19), and maybe also (5,2), (19,18) (but these two last ones are not needed).</p>
  
  <p>I tried:</p>
  
  <pre><code>c.execute('SELECT id as id1 FROM mytable, SELECT id as id2 FROM mytable WHERE abs(id1 - id2) &lt;= 3')
  </code></pre>
  
  <p>but it does not seem to work:</p>
  
  <blockquote>
    <p>sqlite3.OperationalError: near "SELECT": syntax error</p>
  </blockquote>