Search code examples
oracle-databasesyntaxjoinexistsora-00904

Oracle JOIN USING + Subquery : ora-00904 string: invalid identifier


i m having a little syntax problem in my query (simplified) :

select *
from table1 t1
inner join table2 t2 using (pk1)
inner join table3 t3 using (pk2)
where not exists (select1 from table4 t4 where t4.pk1 = t1.pk1)

By using the "using" keyword, oracle doesnt allow table identifier in front of the column name (eg : t1.pk1, only pk1 can be used)

If i write :

select *
from table1 t1
inner join table2 t2 using (pk1)
inner join table3 t3 using (pk2)
where not exists (select1 from table4 t4 where t4.pk1 = pk1)

This query will not give the expected results.

But since i am using an "exists" subquery, how can i join this subquery ?

Of course, i suppose i could write this query another way and avoid the exists, or i could NOT use "using".

But is it possible to have "join / using" combined with a subquery in the where clause ?

Edit : using Oracle 10gR2


Solution

  • Interesting problem! The best I can manage while still using USING is:

    select * from
    ( select *
      from table1 t1
      inner join table2 t2 using (pk1)
      inner join table3 t3 using (pk2)
    ) v
    where not exists (select1 from table4 t4 where t4.pk1 = v.pk1)