title: Join table on itself without two queries
body: <p>I've seen people recommending cross joining a table on itself by doing this:</p>
  
  <pre><code>SELECT *
  FROM tbl AS A, tbl AS B
  WHERE A.col1 = 1 AND B.col1 = 1
  </code></pre>
  
  <p>But here, the engine needs to iterate through all of the rows in tbl twice to match the two queries to the results of A and B, despite the fact that the queries (and therefore the results) are the same.</p>
  
  <p>Assuming that the WHERE on A and B will always be the identical for the two, this is a waste.  Is there any way to query for something once, and then cross join the result of that query on itself?  I'd like to avoid temp tables, which would require disk writing instead of performing this entire thing in RAM.</p>
  
  <p>I am using MySQL, although any SQL answer would help a lot.</p>
  
  <p><strong>EXAMPLE:</strong></p>
  
  <p>Suppose that tbl looks as follows:</p>
  
  <pre><code>COL1    COL2
  1       A
  1       B
  1       C
  2       D
  2       E
  </code></pre>
  
  <p>When I run my where clause of col1 = 1, it returns the first three rows from the above table.  What I want is the following table, but with only one execution of the where statement, since the two tables A and B are identical:</p>
  
  <pre><code>A.COL1    A.COL2    B.COL1    B.COL2
  1         A         1         A
  1         A         1         B
  1         A         1         C
  1         B         1         A
  1         B         1         B
  1         B         1         C
  1         C         1         A
  1         C         1         B
  1         C         1         C
  </code></pre>