title: Create a table as combinations of ranges sqlite3
body: <p>I am attempting to create a table that has combinations of 3 ranges.</p>
  
  <p>Range 1 and Range 2 are equal.</p>
  
  <p>Range 3 is different and a different length.</p>
  
  <p>For any given row the value in Column 1 cannot be equal to the value in Column 2.</p>
  
  <p>e.g. for Range 1: [1-2], Range 2: [1-2], Range 3: [5-7]</p>
  
  <p>the expected result would be:</p>
  
  <pre><code>col1 | col2 | col3 |
  1    | 2    | 5    |
  1    | 2    | 6    |
  1    | 2    | 7    |
  2    | 1    | 5    |
  2    | 1    | 6    |
  2    | 1    | 7    |
  </code></pre>
  
  <p>I'm using the python sqlite3 package so I can use ranges in python. Previously I have been constructing the table using a generator that iterates over the 3 nested ranges as follows:</p>
  
  <pre><code>def all_the_combos():
      for x in range(1,len(all_x)+1):
          for y in range(1,len(all_x)+1):
              if x == y:
                  continue
              for z in range(min(all_z),max(all_z)+1):
              yield (x, y, z) 
  
  cur.execute('BEGIN TRANSACTION')
  cur.executemany('INSERT into All_Combos (x, y, z) Values (?, ?, ?)', all_the_combos())
  </code></pre>
  
  <p>However, this is slow for large ranges and I expect there is some clever way to use joins that would provide better performance. Any advice is appreciated.</p>