Oracle JOIN USING + 子查询:ora-00904 字符串:无效标识符

2024-03-06

我的查询中有一点语法问题(简化):

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)

通过使用“using”关键字,oracle不允许列名前面有表标识符(例如:t1.pk1,只能使用pk1)

如果我写:

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)

此查询不会给出预期结果。

但由于我使用的是“存在”子查询,我如何加入这个子查询?

当然,我想我可以用另一种方式编写这个查询并避免存在,或者我不能使用“using”。

但是是否可以将“join / using”与 where 子句中的子查询结合起来?

编辑:使用Oracle 10gR2


有趣的问题!在使用 USING 的同时我能做到的最好的办法是:

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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Oracle JOIN USING + 子查询:ora-00904 字符串:无效标识符 的相关文章

随机推荐