title: SQL - 2 table values to be grouped by third unconnected value
body: <p>I want to create a graph that pulls data from 2 user questions generated from within an SQL database.</p>
  
  <p>The issue is that the user questions are stored in the same table, as are the answers. The only connection is that the question string includes a year value, which I extract using the <strong>LEFT</strong> command so that I output a column called '<strong>YEAR</strong>' with a list of integer values running from 2013 to 2038 (25 year period). 
  I then want to pull the corresponding answers ('forecast' and 'actual') from each '<strong>YEAR</strong>' so that I can plot a graph with a couple of values from each year (sorry if this isn't making any sense). The graph should show a forecast line covering the 25 year period with a second line (or column) showing the actual value as it gets populated over the years. I'll then be able to visualise if our actual value is close to our original forecast figures (long term goal!)</p>
  
  <p><strong>CODE BELOW</strong></p>
  
  <pre><code>SELECT CAST((LEFT(F_TASK_ANS.TA_ANS_QUESTION,4)) AS INTEGER) AS YEAR,
  -- first select takes left 4 characters of question and outputs value as string then coverts value to whole number.
  CAST((CASE WHEN F_TASK_ANS.TA_ANS_QUESTION LIKE '%forecast' THEN F_TASK_ANS.TA_ANS_ANSWER END) AS NUMERIC(9,2)) AS 'FORECAST',
  CAST((CASE WHEN F_TASK_ANS.TA_ANS_QUESTION LIKE '%actual' THEN ISNULL(F_TASK_ANS.TA_ANS_ANSWER,0) END) AS NUMERIC(9,2)) AS 'ACTUAL'
  -- actual value will be null until filled in each year therefore ISNULL added to replace null with 0.00.
  FROM F_TASK_ANS INNER JOIN F_TASKS ON F_TASK_ANS.TA_ANS_FKEY_TA_SEQ = F_TASKS.TA_SEQ
  WHERE TA_ANS_ANSWER &lt;&gt; ''
  AND (TA_TASK_ID LIKE '%6051' OR TA_TASK_ID LIKE '%6052')
  -- The two numbers above refer to separate PPM questions that the user enters a value into
  </code></pre>
  
  <p>I tried <strong>GROUP BY 'YEAR'</strong> but I get an </p>
  
  <blockquote>
    <p>Error: Each GROUP BY expression must contain at least one column that
    is not an outer reference - which I assume is because I haven't linked
    the 2 tables in any way...</p>
  </blockquote>
  
  <p>Should I be adding a <strong>UNION</strong> so the tables are joined?</p>
  
  <p>What I want to see is something like the following output (which I'll graph up later)</p>
  
  <pre><code>YEAR    FORECAST    ACTUAL
  2013    135000      127331
  2014    143000      145102
  2015    149000           0
  2016    158000           0
  2017    161000           0
  2018... etc
  </code></pre>
  
  <p>Any help or guidance would be hugely appreciated.
  Thanks </p>