title: SQL command not properly ended for Union All
body: <p>I'm having trouble understanding the error on my code. Could somebody help me out?</p>
  
  <p>Here's my sql query</p>
  
  <pre><code>SELECT S.SUBSTR(ASSIGNED_NUMBER, -4) FROM (
     SELECT SUBSTR(ASSIGNED_NUMBER, -4) AS SDATE FROM TBL_DATA1 GROUP BY SUBSTR(ASSIGNED_NUMBER, -4)
     UNION ALL
     SELECT SUBSTR(ASSIGNED_NUMBER, -4) AS SDATE FROM TBL_DATA2 GROUP BY SUBSTR(ASSIGNED_NUMBER, -4)
  ) AS S GROUP BY S.SUBSTR(ASSIGNED_NUMBER, -4);
  </code></pre>
  
  <p><code>Note: Originally, My outer column is S.SDATE and edited it to S.SUBSTR(ASSIGNED_NUMBER, -4)</code>.</p>
  
  <p>Output:</p>
  
  <p><code>ORA-00933: SQL command not properly ended
  00933. 00000 -  "SQL command not properly ended"</code></p>
  
  <p>By the way, the sample date in my <code>ASSIGNED_NUMBER</code> column is <code>58-2016</code>.
  I use substring to get the 2016</p>