How do I SUM a UNION ALL Subquery in Oracle
<p>For the code below, I'm getting the following error message from Oracle: </p>

<blockquote>
  <p>"ORA-00923: FROM keyword not found where expected".</p>
</blockquote>

<pre><code>SELECT
    t1.id,
    t1.code,
    SUM(t1.productCount)
FROM
    (SELECT
        id1,
        code1,
        COUNT(DISTINCT(product)) as productCount1
    FROM
        table1
    GROUP BY
        id1,
        code1

    UNION ALL

    SELECT
        id2,
        code2,
        COUNT(DISTINCT(product2)) as productCount2
    FROM
        table2
    GROUP BY
        id2,
        code2

    UNION ALL

    SELECT
        id3,
        code3,
        COUNT(DISTINCT(product3)) as productCount3
    FROM
        table3
    GROUP BY
        id3,
        code3) t1
GROUP BY
    t1.id,
    t1.code
</code></pre>

<p>Any advice?</p>