title: Oracle Invalid Identifier
body: <pre><code>Error report:
  ORA-00904: "RDD"."USED_END_DATE": invalid identifier
  ORA-02063: preceding line from ADSWEBPROD
  ORA-06512: at line 5
  </code></pre>
  
  <p>The following query is throwing me invalid an identifier error.</p>
  
  <pre class="lang-sql prettyprint-override"><code>DECLARE
    TYPE demo_date_array_type IS TABLE OF dc_demo_dates.demo_date_id%TYPE;
    updated_demo_dates demo_date_array_type;
  BEGIN
    SELECT ddd.demo_date_id 
    BULK COLLECT INTO
      updated_demo_dates
    FROM 
      dc_demo_dates ddd 
    JOIN 
      dc_demo_reservations ddr 
    ON 
      ddd.reservation_id = ddr.reservation_id
      AND ddr.status NOT IN ('DENIED','CANCELLED')
      AND ddr.demo_type &lt;&gt; 'Training'
      AND ddr.environment IS NOT NULL
      AND ddd.last_update_date &gt; SYSTIMESTAMP - 1           -- updated in the last day
      AND ddd.demo_start_date &gt; SYSTIMESTAMP - 14 -- no older than 2 weeks
    JOIN
      (SELECT demo_date_id, used_start_date, used_end_date 
       FROM rps_by_demo_date 
       GROUP BY demo_date_id, used_start_date, used_end_date ) rdd
      ON rdd.demo_date_id = ddd.demo_date_id
    WHERE
      ddd.demo_start_date != NVL(rdd.used_start_date, SYSTIMESTAMP)  -- either start date
      OR ddd.demo_end_date != NVL(rdd.used_end_date, SYSTIMESTAMP);  -- or end date has changed
  END;
  </code></pre>
  
  <p>If I remove the <code>GROUP BY demo_date_id, used_start_date, used_end_date</code> or If I change the last <code>OR</code> for an <code>AND</code>, the code executes successfully (except it doesn't give me the results I need)</p>
  
  <p>Do you know what might be going on?
  Thank you</p>
  
  <p>EDIT:
  I moved the group by clause from the subquery into the main query and obtained the results I wanted. But I still don't understand what was causing the error.</p>