title: SQLite -- joining two subqueries
body: <p>Or at least I think they're called subqueries (newbie and self-trained in SQLite). I have two <code>SELECT</code> statements from two tables in the same database. I would like to join these two subqueries along the columns <code>date</code> and <code>symbol</code>. The subqueries work fine separately, but when I try to <code>JOIN</code> I get an error (<code>error in statement: near "JOIN": syntax error</code>). Here's my query string:</p>
  
  <pre><code>SELECT date, symbol, SUM(oi*contract_settle) AS oi_dollar
      FROM (SELECT date, symbol, oi, contract_settle
              FROM ann
              UNION
              SELECT date, symbol, oi, contract_settle
              FROM qtr) 
      GROUP BY date, symbol
      HAVING oi_dollar &gt; 0
      JOIN
      (SELECT date, symbol, ret FROM crsp
      USING (date, symbol))
  </code></pre>
  
  <p>Thanks!</p>