title: ORA-00904 invalid identifier - but that exists
body: <p>I have a strange Oracle problem with an identifier which works in another subquery of the same query and is defined in the FROM part of the main select. The <code>select coalesce(typ...)</code> returns exactly one row and field. This is the working version of the query:</p>
  
  <pre><code>SELECT
    v.id AS vid, 
    p.name AS pname, 
    v.name,
    TO_CHAR(a.uploaddate,'YYYY-MM-DD HH24:MI:SS') AS scandate,
  
    (SELECT COALESCE(sum(issuecount),0) 
     FROM foldercountcache fc, folder f 
     WHERE fc.folder_id = f.id 
      AND fc.projectversion_id = v.id AND f.name like '1 -%'
    ) as crit,
  
    (SELECT COALESCE(typ,'No Issues') FROM
     (SELECT ROWNUM AS r,cri,typ,n FROM
      (SELECT f.name AS cri,i.issuetype AS typ, count(i.issuetype) as n
       FROM issue i 
       LEFT JOIN folder f ON i.projectversion_id = f.projectversion_id AND i.folder_id = f.id 
       WHERE (i.projectversion_id = 15284846 AND f.name like '1%') 
       GROUP BY f.name,i.issuetype 
       ORDER BY cri, n DESC
      ) 
     ) WHERE r=2
    ) AS top2
  
  FROM projectversion v INNER JOIN project p ON p.id = v.project_id 
   INNER JOIN artifact a ON a.projectversion_id = v.id
  WHERE a.uploaddate = 
   (SELECT max(uploaddate) 
    FROM artifact 
    WHERE projectversion_id = v.id AND status = 'PROCESS_COMPLETE'
   )
  ORDER BY p.name, v.name, a.uploaddate ;
  </code></pre>
  
  <p>I need to replace the number <code>15284846</code> with <code>v.id</code>. However, doing this I receive the
  <code>ORA-00904 "V"."ID" invalid identifier</code> 
  error from Oracle.
  Please note, that the <code>v.id</code> is used without problem in the first subselect which begins with <code>select COALESCE</code> </p>
  
  <p>What is wrong here?</p>