I’m having the error ORACLE: ORA-00904: Invalid Identifier on:
and l.cd_pergunta = e.cd_pergunta
the invalid identifier is ‘e’, the prefix of cd_pergunta…
When i execute this query:
select count(*)
from TEACEITE e
inner join TEREGETA re on re.cd_etapa = e.cd_etapa
and re.id_reg_neg = 1.00000000
where e.obrigatorio = 1
and not exists
(select 1
from GESESSAO s
inner join GERESPOS r on r.sessao = s.sessao_resp
and r.resposta_log = 1
inner join GEEPE l on l.cd_quest = s.cd_quest
and l.ord_perg = r.ord_pergunta
and l.cd_pergunta = e.cd_pergunta
where s.cd_quest = e.cd_quest
and s.item = e.cd_etapa
and s.origem = 'GC'
and s.os_nf_orc_cont = 1.00000000)
Any idea?
The problem is that the alias e is not available within the nested select and hence the “invalid identifier”.
You can try to rewrite the query so that the conditions
s.cd_quest = e.cd_quest and s.item = e.cd_etapaare part of the main select instead of the nested select.EDIT: I tried a few scenarios and the problem is that the alias e is not available during join resolution in the nested query. Looks like you cannot refer to an outer table alias in the join condition of the inner query.
I believe that the following will work
While this query may work, I am not sure if its accomplishing what you want, please ensure that your business logic is taken care of as well.